运行struts2应用时,页面虽然没有报错,但是Tomcat的日志中出现如下的警告。
[WARNING] No configuration found for the specified action: '/login' in namespace: '/'. Form action defaulting to 'action' attribute's literal value.
但是页面为什么没有报错呢,使用了什么默认的机制使得login这个action还是被找到了呢?
分析原因,原来的namespace(或者说是contextroot)后面找不到"/login"这的action。
实际上struts.xml文件中,将action名字定义成了login。
<package name="default" namespace="/" extends="struts-default">
<action name="login"
class="com.maven.struts2.LoginAction">
<result name="success">/WEB-INF/pages/UserInfo.jsp</result>
<result name="error">/WEB-INF/pages/Login.jsp</result>
</action>
</package>
而在jsp页面中,在定义action时,多加了一个“/”,使得jsp页面的定义与struts.xml的定义不匹配。
<s:form action="/login" method="post">
<s:textfield name="username" key="label.username" size="20" />
<s:password name="password" key="label.password" size="20" />
<s:submit method="execute" key="label.login" align="center" />
</s:form>
要修改的去除这个警告的话,只需要在上面的jsp页面中将"/"去除即可。
相关连接http://stackoverflow.com/questions/20641441/warning-no-configuration-found-for-the-specified-action-in-namespace-form-act