No configuration found for the specified action警告异常的解决方案

来源:互联网 发布:ubuntu安装源位置 编辑:程序博客网 时间:2024/05/16 00:32

异常信息如下:

2015-7-15 11:52:36 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
警告: No configuration found for the specified action: 'Login' in namespace: '/admin'. Form action defaulting to 'action' attribute's literal value.
2015-7-15 11:52:36 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
警告: No configuration found for the specified action: 'Login' in namespace: '/admin'. Form action defaulting to 'action' attribute's literal value.


出现这类异常的通常情况是struts.xml和你的jsp页面的namespace不对应。


我的struts.xml文档如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>


<package name="struts2" namespace="/" extends="struts-default">


<action name="Login" class="UserAction" method="login">
   <result name="admin" type="redirectAction">ListUsers</result>
   <result name="user">/global/success.jsp</result>
   <result name="failure">/global/failure.jsp</result>
   <result name="input">/index.jsp</result>
</action>


<action name="Register" class="UserAction" method="addUser">
   <result type="redirect">/users/register.jsp</result>
   <result name="addSuccess">/global/success.jsp</result>
   <result name="addFailure">/global/failure.jsp</result>
</action>


<action name="ListUsers" class="UserAction" method="queryAllUser">
   <result name="success">/admin/listUsers.jsp</result>
</action>


<action name="DeleteUser" class="UserAction" method="deleteUser">
<result name="success">/global/success.jsp</result>
<result name="input">/global/failure.jsp</result>
</action>


<action name="EditUser" class="UserAction" method="editUser">
   <result name="success">/global/success.jsp</result>
   <result name="input">/global/failure.jsp</result>
</action>


<action name="QueryById" class="UserAction" method="queryUserById">
   <result>/admin/editUser.jsp</result>
</action>


</package>


</struts>


发生异常的jsp代码片段:

  <s:form name="form1" action="Login" method="post" onsubmit="return checkLogin()">
  <div><s:textfield id="userName" name="user.userName" label="用户名"/><s:label id="userMsg"/></div>
  <div><s:password id="password" name="user.password" label="密码"/> <s:label id="pwdMsg"/></div>
  <s:hidden name="role" value="admin"/>
  <s:submit value="登录"/>
  </s:form>


出现异常的原因:

jsp与struts.xml配置的默认命名空间不一样。


解决方法:

1.在struts中配置<package name="struts2" namespace="/" extends="struts-default">。相应的在jsp页面中配置  <s:form name="form1" action="Login" method="post" onsubmit="return checkLogin()" namespace="/">;

2.如果在struts.xml中指定命名空间的名字,如<package name="struts2" namespace="/hello" extends="struts-default">。那么在jsp页面中就应该配置<s:form name="form1" action="Login" method="post" onsubmit="return checkLogin()" namespace="/hello">;

0 0
原创粉丝点击