用的是struts1,ActionForm類如下:
private String menuType; private ClientUser user; ...相應的get和set方法...
Action類如下:
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { System.out.println(" =========進入UserInfoAction類========="); UserInfoForm userInfoForm = (UserInfoForm) form; }
但是在進行表單提交的時候碰到下面的問題:
=========進入UserInfoAction類========= 2012-4-20 17:24:46 org.apache.catalina.core.StandardWrapperValve invoke 嚴重: Servlet.service() for servlet action threw exception java.lang.IllegalArgumentException: No bean specified at org.apache.commons.beanutils.PropertyUtilsBean.getPropertyDescriptor(PropertyUtilsBean.java:751) at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:937) at org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:811) at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:298) at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:493) at org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:816) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at com.udrm.bms.struts.beans.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:54) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Unknown Source)
如果我不進行表單提交,那麼是沒有錯誤的,只要進行表單提交了就有錯誤。很顯然,這個是進入了Action類的execute方法的,通過debug調試發現,當UserInfoForm userInfoForm = (UserInfoForm)form擷取表單值得時候就報錯了。從網上尋找了一些資料,說在ActionForm中只要是自訂的對象的屬性,那麼都需要進行初始化new 一下這個對象。也就是我的ActionForm需要改為:
private String menuType; [color=red][b]private ClientUser user=new ClientUser();//必須new一下 [/b][/color] ...相應的get和set方法...
解決!!