struts.xml配置文件详解
一、常量配置方式一
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<!-- 1、乱码解决 -->
<constant name="struts.il8n.encoding" value="UTF-8"></constant>
<!--2、 自定义扩展名 -->
<constant name="struts.action.extension" value="action,,siggy"></constant>
<!-- 3、友好的提升信息,设置开发模式 -->
<constant name="struts.devMode" value="true"></constant>
<!-- 设置配置文件自动加载,推荐在开发中使用。 -->
<constant name="struts.configuration.xml.reload" value="true"></constant>
</struts>
二、常量配置方式二
在src下添加struts.properties配置文件。
三、团队协作开发配置。
<!-- 通过include添加不同人员的配置文件 -->
<include file="Action/user.xml"></include>
四、配置文件的加载顺序。
struts-default.xml ---> struts-plugin.xml -----> struts.xml
五、package配置。
在struts.xml文件中package元素用于定义包配置,每个package元素定义了一个包配置。它的常用属性有:
l na
me:必填属性,用来指定包的名字。
l extends:可选属性,用来指定该包继承其他包。继承其它包,可以继承其它包中的Action定义、拦截器定义等。
l namespace:可选属性,用来指定该包的命名空间。
<!--包的名称自定义,可以配置多个包 ,命名空间: namespace="/"表示根路径,默认是根路径,
不同的模块可以指定不同的空间。 -->
<package name="Login" namespace="/user" extends="struts-default">
<action name="login" class="Action.LoginAction">
<!-- /success.jsp,"/"表示访问根路径下的jsp文件。 -->
<result name="success">/success.jsp</result>
<result name="failed">/login.jsp</result>
</action>
</package>
http://localhost:8080/userlogin_struts2/user/login.action。
因此对于<form></form>表单的填写也应该相对应:
<form action="user/login.action" method="post">
帐号:<input type="text" name="name"><br>
密码:<input type="password" name="pwd"><br>
<input type="submit" value="登录">
</form>