首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

怎样使用标签和strust区别在一个form中的2个按钮的行为解决方案

2012-01-15 
怎样使用标签和strust区别在一个form中的2个按钮的行为前台代码:html:formaction /testAction.do meth

怎样使用标签和strust区别在一个form中的2个按钮的行为
前台代码:
<html:form   action= "/testAction.do "   method= "post ">
.........
      <html:submit   property= "action "   value= "增加 ">
                        <bean:message   key= "button.add "/> </html:submit>
                        <div   align= "center "> </div> </td>
                    <td   height= "25 "> <div   align= "center ">
                        <html:submit   property= "action "   value= "修改 ">
                        <bean:message   key= "button.updata "/> </html:submit>
                    </div> </td>

testAction的代码:

package   ems.struts;

import   java.util.HashMap;
import   java.util.Map;
import   javax.servlet.http.HttpServletRequest;
import   javax.servlet.http.HttpServletResponse;
import   org.apache.struts.action.ActionForm;
import   org.apache.struts.action.ActionForward;
import   org.apache.struts.action.ActionMapping;
import   org.apache.struts.actions.LookupDispatchAction;

public   class   testAction   extends   LookupDispatchAction   {
        protected   Map   getKeyMethodMap()
        {
                HashMap   map=new   HashMap();
                map.put( "button.add ", "add ");//button.delete,按钮的   message   key
                  map.put( "button.update ",   "update ");
                return   map;

      }
          public   ActionForward   add(ActionMapping   mapping,
                                                                  ActionForm   form,
                                                                  HttpServletRequest   request,
                                                                  HttpServletResponse   response)
          {
                System.out.println( "add ");
                return   null;
        }
        public   ActionForward   update(ActionMapping   mapping,
                                                                    ActionForm   form,


                                                                      HttpServletRequest   request,
                                                                    HttpServletResponse   response)
        {
                  System.out.println( "updata ");
                return   null;
        }


        }
配置文件   :::的代码:
<action     parameter= "action "   path= "/testAction "   type= "ems.struts.testAction ">
            <forward   name= "plan_eng_reg "   path= "/Basic_Data/plan_eng_reg.jsp "   />

在资源文件ApplicationResources.properties中
button.add=add
button.updata=updata

在运行时出现如下错误!

javax.servlet.jsp.JspException:   Cannot   retrieve   definition   for   form   bean   null   on   action   /testAction.do
at   org.apache.struts.taglib.html.FormTag.lookup(FormTag.java:731)
at   org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:419)
at   jsp_servlet._basic_data.__plan_eng_reg._jspService(__plan_eng_reg.java:305)
at   weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
at   weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1072)
at   weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:465)
at   weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:348)
at   weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6981)
at   weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at   weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at   weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3892)
at   weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2766)
at   weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
at   weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)


[解决办法]
在你的form中查看一下是否有action这个变量
[解决办法]
form 有没有定义testAction使用的form?
[解决办法]
在struts-config.xml配置文件中为action定义一个formbean啊,如
<form-bean name= "testForm " type= "xxx ">
<form-property name= " " type= " "/>
</form-bean>

<action
name= "testForm "
path= "/testAction "
type= "ems.struts.testAction "
parameter= "action ">
<forward name= "plan_eng_reg " path= "/Basic_Data/plan_eng_reg.jsp " />
</action>

[解决办法]
配置文件 :::的代码:
<action parameter= "action " path= "/testAction " type= "ems.struts.testAction ">


<forward name= "plan_eng_reg " path= "/Basic_Data/plan_eng_reg.jsp " />
改为:
<action parameter= "action " path= "/testAction " name= "testActionForm " type= "ems.struts.testAction ">
<forward name= "plan_eng_reg " path= "/Basic_Data/plan_eng_reg.jsp " />

热点排行