日期:2014-05-18  浏览次数:20676 次

这段JSP代码,有问题吗?
<%@ page language="java" contentType="text/html;charset=gb2312" %>
<%!
public String RequestGet(String s)
{
if (s == null || s.equals(""))
{return " ";}
else
{
String rStr=request.getParameter(s);
if(rStr==null){rStr="";}
rStr= new String(rStr.getBytes("ISO-8859-1"));
rStr=CheckReplace(rStr);
return rStr;
}
}
%>

运行时出错,如下:
An error occurred at line: 10 in the jsp file: /service/function.jsp
request cannot be resolved
7: {return " ";}
8: else
9: {
10: String rStr=request.getParameter(s);
11: if(rStr==null){rStr="";}
12: rStr= new String(rStr.getBytes("ISO-8859-1"));
13: rStr=CheckReplace(rStr);

------解决方案--------------------
在jsp页面定义方法好像不大妥当吧,你这个方法难道还想在其他的地方调用?
------解决方案--------------------
真是很佩服楼主在jsp中这样写代码,
<%!
%>
在这中表达式,根本用不了httpservletrequest 的request
所以 :String rStr=request.getParameter(s); 
这句话就错了。。。
------解决方案--------------------
<%! %>中的代码段类似于静态成员
static