用struts2做了一个简单的入门程序,运行成功了,但是总出现这个警告:
警告: No configuration found for the specified action: 'checkLogin' in namespace: ''. Form action defaulting to 'action' attribute's literal value.
虽说对系统的运行没什么影响,但是看着感觉很不舒服,所以想办法解决了。
login.jsp页面的相关源码:
- <s:form action="checkLogin" method="post">
- <s:textfield name="username" label="用户名:"></s:textfield>
- <s:password name="password" label="密码:"></s:password>
- <s:submit value="登陆"></s:submit>
- </s:form>
struts.xml的配置如下:
- <package name="struts" namespace="/" extends="struts-default">
- <action name="checkLogin" class="action.LoginAction" method="checkLogin">
- <result name="success">/index.jsp</result>
- <result name="login">/login.jsp</result>
- </action>
- </package>
解决办法:在login.jsp页面的form标记里加上属性 namespace="/",即:
<s:form action="checkLogin" method="post" namespace="/">
总之,这两个地方的namespace的属性值要一模一样,不能省略,否则就出现这样的警告。
转载自:http://blog.csdn.net/lingxue1027/article/details/8514284