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

小弟求救
小弟做的一个简单的say hello 程序
在不输入名字和输入monster时出输出一个错误信息
正常输入运行是正常的,但以上2个验证就是有错误
应该是验证是有问题,可我想不出问题在哪里

错误信息是:
服务器遇到内部错误,无法满足这个访问请求

异 常 

org.apache.jasper.JasperException: org.apache.struts.action.ActionMessage
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:395)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
org.apache.struts.action.RequestProcessor.internalModuleRelativeForward(RequestProcessor.java:1012)
org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:980)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:255)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1480)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:524)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


起 因 

java.lang.ClassCastException: org.apache.struts.action.ActionMessage
org.apache.struts.taglib.html.ErrorsTag.doStartTag(ErrorsTag.java:215)
org.apache.strutsel.taglib.html.ELErrorsTag.doStartTag(ELErrorsTag.java:180)
org.apache.jsp.hello_jsp._jspx_meth_html_errors_0(hello_jsp.java:225)
org.apache.jsp.hello_jsp._jspx_meth_html_html_0(hello_jsp.java:137)
org.apache.jsp.hello_jsp._jspService(hello_jsp.java:92)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
org.apache.struts.action.RequestProcessor.internalModuleRelativeForward(RequestProcessor.java:1012)
org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:980)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:255)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1480)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:524)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

两处验证的代码如下:
if(userName.equalsIgnoreCase(badUserName)){
error.add("username",new ActionMessage("hello.dont.talk.to.monster",badUserName));
saveErrors(request,error);
return(new ActionForward(mapping.getInput()));
}

public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
// TODO Auto-generated method stub
ActionErrors errors=new ActionErrors();
if((userName==null)||userName.length()<1)
errors.add("username", new ActionMessage("hello.no.username.error"));
return errors;
}

------解决方案--------------------
if(userName.eq