警告: No configuration found for the specified action: 'loginPerson' in namespace: ''. Form action def

来源:互联网 发布:电工理论与新技术 知乎 编辑:程序博客网 时间:2024/04/30 03:22

      用struts2写一个登陆小程序,结果tamcat抛了这样的异常:

警告: No configuration found for the specified action: 'loginPerson' in namespace: ''. Form action defaulting to 'action' attribute's literal value.
2012-8-21 13:41:48 com.opensymphony.xwork2.util.logging.jdk.JdkLogger warn
警告: No configuration found for the specified action: 'loginPerson' in namespace: ''. Form action defaulting to 'action' attribute's literal value.

这个问题折腾了半天,有的人还说struts.xml要加ation名称后面要加.action  我整理了两种解决上述警告的方法:

   第一种:采用系统的默认名空间

   struts.xml配置:

  <package name="main" extends="struts-default" >
<global-results>
<result name="login">/login.jsp</result>
</global-results>
  <action name="loginPerson" class="com.helloweenvsfei.struts2.action.LoginAction" >
<result name="success">/success.jsp</result>
</action>
</package>
  </struts>

jsp页面的主要配置:

<body>
    <struts:form  action="loginPerson" method="post" >
    <struts:label value="登陆系统"></struts:label>
    <struts:textfield name="account" label="账号"></struts:textfield>
    <struts:password name="password" label="密码"></struts:password>
    <struts:submit value="登陆"></struts:submit>
    </struts:form>
  </body>

此时jsp页面的此action的路径会被解析为/myApp/loginPerson.action

      第二种: 采用自定义命名空间

       struts.xml配置:

       <package name="main" extends="struts-default" namespace="/hello">
          <global-results>
<result name="login">/login.jsp</result>
          </global-results>
  <action name="loginPerson" class="com.helloweenvsfei.struts2.action.LoginAction" >
<result name="success">/success.jsp</result>
</action>
</package>

        jsp页面的配置:

         <body>
    <struts:form  action="loginPerson" method="post" namespace="/hello">
    <struts:label value="登陆系统"></struts:label>
    <struts:textfield name="account" label="账号"></struts:textfield>
    <struts:password name="password" label="密码"></struts:password>
    <struts:submit value="登陆"></struts:submit>
    </struts:form>
      </body>

此时jsp页面的action路径会被解析为/myApp/hello/loginPerson

另外不管是哪种配置的struts.xml中的action的名称会被struts自动追加.action后缀,所以不管是那种配置方法都不应该将action的名称配置为***.action

原创粉丝点击