Struts2之form标签的action及namespace属性的组合使用

来源:互联网 发布:java编写贪吃蛇教程 编辑:程序博客网 时间:2024/06/04 23:24

jsp页面:

<s:form name="login" method="post" action="login" namespace="/hello" >

struts.xml文件:

<struts>
    <package name="users" namespace="/hello" extends="default">
    <actionname="login" class="com.loginAction" method="login">
    ······
    </action>
    </package>

<struts>

解释:

jsp页面中form标签的action属性对应于struts.xml文件中action标签的name属性

jsp页面中form标签的namespace属性对应于struts.xml文件中package标签的namespace属性

注意:

1.不能写成<s:form name="login" method="post" action="login.action" namespace="/hello" > 

.action不能由我们手工添加,Struts2会自动为你完成这个工作。不然会出现以下错误:

警告:No configuration found for the specified action: 'ShowMessage' in namespace: ''. Form action defaulting to 'action' attribute's literal value. 

2.尽量不要写成<s:form name="login" method="post" action="/hello/login" >

既然Struts2为我们提供了namespace属性,使用它让我们的代码更规范。






原创粉丝点击