我正在研究struts1.2应用程序.我创建了一个扩展validatorform的formbean,然后重写方法validate().
然后当我运行流程时.它给了我错误.
Aug 21, 2011 8:42:07 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.ClassCastException: org.apache.struts.action.ActionMessage cannot be cast to org.apache.struts.action.ActionError
at org.apache.struts.taglib.html.ErrorsTag.doStartTag(ErrorsTag.java:215)
at org.apache.jsp.SubmitPost_jsp._jspx_meth_html_005ferrors_005f0(SubmitPost_jsp.java:552)
at org.apache.jsp.SubmitPost_jsp._jspService(SubmitPost_jsp.java:270)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:274)
at org.apache.struts.action.RequestProcessor.internalModuleRelativeForward(RequestProcessor.java:1012)
at org.apache.struts.tiles.TilesRequestProcessor.internalModuleRelativeForward(TilesRequestProcessor.java:345)
at org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:980)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:255)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:851)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:257)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1764)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Aug 21, 2011 8:42:07 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [action] in context with path [/streetshop] threw exception [java.lang.ClassCastException: org.apache.struts.action.ActionMessage cannot be cast to org.apache.struts.action.ActionError] with root cause
java.lang.ClassCastException: org.apache.struts.action.ActionMessage cannot be cast to org.apache.struts.action.ActionError
at org.apache.struts.taglib.html.ErrorsTag.doStartTag(ErrorsTag.java:215)
at org.apache.jsp.SubmitPost_jsp._jspx_meth_html_005ferrors_005f0(SubmitPost_jsp.java:552)
at org.apache.jsp.SubmitPost_jsp._jspService(SubmitPost_jsp.java:270)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:274)
at org.apache.struts.action.RequestProcessor.internalModuleRelativeForward(RequestProcessor.java:1012)
at org.apache.struts.tiles.TilesRequestProcessor.internalModuleRelativeForward(TilesRequestProcessor.java:345)
at org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:980)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:255)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:851)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:257)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1764)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
DEBUG [http-apr-8080-exec-12] (RequestUtils.java:1799) - Get module name for path /Postaddd.do
DEBUG [http-apr-8080-exec-12] (RequestUtils.java:1821) - Module name found: default
DEBUG [http-apr-8080-exec-12] (RequestProcessor.java:225) - Processing a 'GET' for path '/Postaddd'
DEBUG [http-apr-8080-exec-12] (RequestUtils.java:764) - Looking for ActionForm bean instance in scope 'request' under attribute key 'PostadddForm'
DEBUG [http-apr-8080-exec-12] (RequestUtils.java:839) - Creating new ActionForm instance of type 'bseller.postadd.PostaddForm'
DEBUG [http-apr-8080-exec-12] (RequestUtils.java:844) - --> bseller.postadd.PostaddForm@3b061299
DEBUG [http-apr-8080-exec-12] (RequestProcessor.java:372) - Storing ActionForm bean instance in scope 'request' under attribute key 'PostadddForm'
DEBUG [http-apr-8080-exec-12] (RequestProcessor.java:813) - Populating bean properties from this request
DEBUG [http-apr-8080-exec-12] (BeanUtils.java:792) - BeanUtils.populate(bseller.postadd.PostaddForm@3b061299, {dispatch=[Ljava.lang.String;@baf1915})
DEBUG [http-apr-8080-exec-12] (BeanUtils.java:873) - setProperty(bseller.postadd.PostaddForm@3b061299, dispatch, [showSubmitPostPage])
DEBUG [http-apr-8080-exec-12] (RequestProcessor.java:940) - Validating input form properties
INFO [http-apr-8080-exec-12] (PostaddForm.java:119) - validate method called
INFO [http-apr-8080-exec-12] (PostaddForm.java:122) - Email Id: null
DEBUG [http-apr-8080-exec-12] (RequestProcessor.java:972) - Validation failed, returning to '/SubmitPost.jsp'
DEBUG [http-apr-8080-exec-12] (RequestProcessor.java:1010) - Delegating via forward to '/SubmitPost.jsp'
DEBUG [http-apr-8080-exec-12] (PropertyMessageResources.java:177) - getMessage(en_SG,errors.header)
DEBUG [http-apr-8080-exec-12] (PropertyMessageResources.java:269) - loadLocale(en_SG)
DEBUG [http-apr-8080-exec-12] (PropertyMessageResources.java:177) - getMessage(en_SG,errors.footer)
DEBUG [http-apr-8080-exec-12] (PropertyMessageResources.java:269) - loadLocale(en_SG)
DEBUG [http-apr-8080-exec-12] (PropertyMessageResources.java:177) - getMessage(en_SG,errors.prefix)
DEBUG [http-apr-8080-exec-12] (PropertyMessageResources.java:269) - loadLocale(en_SG)
DEBUG [http-apr-8080-exec-12] (PropertyMessageResources.java:177) - getMessage(en_SG,errors.suffix)
DEBUG [http-apr-8080-exec-12] (PropertyMessageResources.java:269) - loadLocale(en_SG)
Aug 21, 2011 8:42:16 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.ClassCastException: org.apache.struts.action.ActionMessage cannot be cast to org.apache.struts.action.ActionError
at org.apache.struts.taglib.html.ErrorsTag.doStartTag(ErrorsTag.java:215)
at org.apache.jsp.SubmitPost_jsp._jspx_meth_html_005ferrors_005f0(SubmitPost_jsp.java:552)
at org.apache.jsp.SubmitPost_jsp._jspService(SubmitPost_jsp.java:270)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:274)
at org.apache.struts.action.RequestProcessor.internalModuleRelativeForward(RequestProcessor.java:1012)
at org.apache.struts.tiles.TilesRequestProcessor.internalModuleRelativeForward(TilesRequestProcessor.java:345)
at org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:980)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:255)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:851)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:257)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1764)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Aug 21, 2011 8:42:16 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [action] in context with path [/streetshop] threw exception [java.lang.ClassCastException: org.apache.struts.action.ActionMessage cannot be cast to org.apache.struts.action.ActionError] with root cause
java.lang.ClassCastException: org.apache.struts.action.ActionMessage cannot be cast to org.apache.struts.action.ActionError
at org.apache.struts.taglib.html.ErrorsTag.doStartTag(ErrorsTag.java:215)
at org.apache.jsp.SubmitPost_jsp._jspx_meth_html_005ferrors_005f0(SubmitPost_jsp.java:552)
at org.apache.jsp.SubmitPost_jsp._jspService(SubmitPost_jsp.java:270)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:274)
at org.apache.struts.action.RequestProcessor.internalModuleRelativeForward(RequestProcessor.java:1012)
at org.apache.struts.tiles.TilesRequestProcessor.internalModuleRelativeForward(TilesRequestProcessor.java:345)
at org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:980)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:255)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:851)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:257)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1764)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
请告诉我我可以做的是我的设置.
<action path="/Postaddd"
type="bseller.postadd.PostaddAction"
parameter="dispatch"
scope="request"
validate="true"
input="/SubmitPost.jsp"
name="PostadddForm">
<forward name="posterror" path="ordererror.page"/>
<forward name="successPost" path="bseller.successPost.page"/>
</action>
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
{
Logger log= Logger.getLogger("BSELLER_APPLICATION");
log.info("validate method called");
ActionErrors errors = new ActionErrors();
log.info("Email Id: " + getEmailid());
if(!Validation.isValidEmailAddress(getEmailid()))
{
errors.add("emailid", new ActionMessage("prompt.email.error"));
}
if(!Validation.isPhoneNumberValid(getMobile()))
{
errors.add("mobile", new ActionMessage("prompt.contactno.error"));
}
if(!Validation.isNumeric(getPrice()))
{
errors.add("price", new ActionMessage("prompt.price.error"));
}
return errors;
}
解决方法:
我只是遇到了同样的问题我将所有ActionMessage更改为ActionError并且它有效,听起来像struts 1我必须这样做不确定但这对我有帮助.
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
{
.......
if(!Validation.isValidEmailAddress(getEmailid()))
{
errors.add("emailid", new ActionError("prompt.email.error"));
}
if(!Validation.isPhoneNumberValid(getMobile()))
{
errors.add("mobile", new ActionError("prompt.contactno.error"));
}
if(!Validation.isNumeric(getPrice()))
{
errors.add("price", new ActionError("prompt.price.error"));
}
return errors;
}