java - org.apache.struts.action.ActionMessage无法转换为org.apache.struts.action.ActionError

我正在研究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;
    }

本文翻译自 https://stackoverflow.com/questions/7138384/

网站遵循 CC BY-SA 4.0 协议,转载或引用请注明出处。

标签 java struts struts-config


相关文章:

java - java.lang.OutOfMemoryError使用带有多任务的库

java - 为什么我们不需要为静态方法创建对象?

java - Microsoft的MVC是新型的Struts for Dot网吗?

java - Java Web应用程序中的异常处理

java - 在Tomcat 5.5中部署web-app时如何解决Error listenerStart?

java - Java中的立方B样条曲线

java - Struts Tiles 1-嵌套磁贴问题

java - java struts.xml中的差异路径类型是什么?

java - 获取JSON弹出窗口以保存或打开对话框而不是实际内容?

java - 您可以在struts-config.xml中使用正则表达式吗?