如何使用DynaActionForm

如何使用DynaActionForm?
1.在struts-config.xml中:
<form-bean name="uploadForm" type="org.apache.struts.action.DynaActionForm"> 
    <form-property name="upload" type="org.apache.struts.upload.FormFile"/> 
    <form-property name="url" type="java.lang.String"/>
    <form-property name="desc" type="java.lang.String"/>
</form-bean>

2.JSP在使用taglib没有变化;

3.在Action中使用DynaActionForm时需要注意:
DynaActionForm edFrm=(DynaActionForm)form;
String name= (String)edFrm.get("name");

4.直接使用DynaActionForm,会使使用者丧失使用validate和reset的机会,此时就需要从DynaActionForm
派生出一个子类,然后覆盖validate、reset方法。在派生类中检索属性,使用:this.get("...")

如何创建一个DynaActionForm对象?
答:这种情况出现在通过一个列表选择,然后加载被选择的对象并在细节窗体中显示。此时,不能直接创建DynaActionForm。否则,在使用DynaActionForm的set方法会抛出空指针异常。正确的方法例子:
DynaActionForm edFrm= (DynaActionForm)request.getAttribute( mapping.getAttribute());
......
edFrm.set( "id", new Integer(ur.getId()));
edFrm.set( "name", ur.getName());
edFrm.set( "pwd1", ur.getPassword());
edFrm.set( "pwd2", ur.getPassword());
......
request.setAttribute( mapping.getAttribute(), edFrm);

究其原因是通过new创建的DynaActionForm中并不包含任何属性,在set时找不到当然就是空指针异常啦。

DynaActionForm的问题

01-05

jsp页面用了几个struts标签rnrn rn rnrnrnstruts-config.xmlrnrn rn rn rn rn rn rn rn rn rn rn rn rn rnrnrn然后访问jsp页面的时候报异常rnorg.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: Exception creating bean of class org.apche.struts.action.DynaActionForm: 1rn org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)rn org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)rn org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)rn org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:717)rnrn控制台里空指针异常rn严重: Error creating form bean of class org.apche.struts.action.DynaActionFormrnjava.lang.NullPointerExceptionrn at org.apache.struts.config.FormBeanConfig.createActionForm(FormBeanConfig.java:289)rn at org.apache.struts.util.RequestUtils.createActionForm(RequestUtils.java:254)rn at org.apache.struts.util.RequestUtils.createActionForm(RequestUtils.java:208)rn at org.apache.struts.taglib.html.FormTag.initFormBean(FormTag.java:505)rn at org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:482)rn at org.apache.jsp.test.register_jsp._jspx_meth_html_005fform_005f0(register_jsp.java:97)rn at org.apache.jsp.test.register_jsp._jspService(register_jsp.java:70)rn at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)rn at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)rn at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)rn at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)rn at java.lang.Thread.run(Thread.java:619)rnrn用的struts1.38,用普通的ActionForm正常

struts的validate验证框架问题DynaActionForm

07-25

使用了DynaActionForm后还能进行Validator验证框架验证吗?rn 如果换成了DynaValidatorForm后可以通过验证框架,DynaValidatorForm是DynaActionForm的子类,我想不到为什么不能?rn Action继承的是DispatchActionrn 下面是抛出来的错误rn javax.servlet.jsp.JspException: ServletException in '/task/newTask.jsp': Exception creating bean of class org.apache.struts.action.DynaValidatorForm: 1rn at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:923)rn at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:462)rn at org.apache.jsp.task.templateTask_jsp._jspx_meth_tiles_insert_1(templateTask_jsp.java:180)rn at org.apache.jsp.task.templateTask_jsp._jspService(templateTask_jsp.java:129)rn at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rn at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)rn at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)rn at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)rn at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)rn at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)rn at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)rn at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)rn at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1063)rn at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:263)rn at org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition(TilesRequestProcessor.java:239)rn at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:302)rn at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:229)rn at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)rn at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)rn at task.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:22)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)rn at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)rn at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)rn at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)rn at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)rn at java.lang.Thread.run(Thread.java:619)

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试

关闭