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

关于struts 中 <html:errors/>的问题
我在actionform   中是这样写validate的   但是一旦在输入页面中加入 <html:errors/>   当输入“a”时就提示错误异常   不加 <html:errors/> 就没问题   输入“a”时页面跳到输入页面   只不过错误信息没办法显示出来   这是为什么啊?

下面是actionform   中的   validate

public   ActionErrors   validate(ActionMapping   mapping,HttpServletRequest   request){
ActionErrors   errors=   new   ActionErrors();
if   (name.equals( "a ")){

errors.add( "name ",new   ActionMessage( "emp.name "));

}
return   errors;
}

这是输入页面出现的错误提示:


The   server   encountered   an   internal   error   ()   that   prevented   it   from   fulfilling   this   request.

例外  

org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
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:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


原因  

java.lang.ClassCastException
org.apache.struts.taglib.html.ErrorsTag.doStartTag(ErrorsTag.java:215)
org.apache.jsp.index_jsp._jspx_meth_html_errors_0(index_jsp.java:223)
org.apache.jsp.index_jsp._jspx_meth_html_form_0(index_jsp.java:147)
org.apache.jsp.index_jsp._jspService(index_jsp.java:91)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
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:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)



------解决方案--------------------
在资源配置文件中对emp.name赋上值了吗?
------解决方案--------------------
mark
-