struts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<!-- 配置常量
struts.devMode:开发模式
修改struts.xml配置文件能马上反馈
-->
<constant name="struts.devMode" value="true"/>
<!--设置action的后缀
<constant name="struts.action.extension" value="do"/>
<!-- 解决中文乱码 ,2.1.7以后才能用 <constant name="struts.i18n.encoding" value="UTF-8"/> --> <!-- <constant name="struts.ognl.allowStaticMethodAccess" value="true"/> 允许jsp访问静态方法--> <!-- <include file="login.xml"/> 包含其他struts2配置文件--> <!-- <constant name="struts.ui.theme" value="simple"/> 设置主题默认为:xhtml--> <!-- namespaca决定了action的访问路径,默认为"",可以接受所有路径的action namespace可以写为/,或者/xx,或者/xxx/yyy,对应的action访问路径为/index.action,/xxx/index.action,或者/xxx/yyy/index.action --> <package name="defalut" namespace="/" extends="struts-default"> <!-- 如果不配置class属性,则默认调用struts2的默认action(ActionSupport) method:指定调用的是class里的哪个方法,默认为execute (也可以使用动态方法调用DMI :Struts2_test/hello_struts!add) --> <action name="hello_struts" class="com.struts2.ActionTest.IndexAction1" method="add"> <!-- name="success"可以省略,为默认值 --> <result name="success">/WEB-INF/Hello.jsp</result> </action> <action name="hello_struts*" class="com.struts2.ActionTest.IndexAction{1}"> <!-- name="success"可以省略,为默认值 type="dispatcher"为默认值,只能跳转到页面 type="redirect",客户端重定向到新的页面 type="chain",服务器端重定向到另外一个action type="chain",客户端重定向到另外一个action type="redirectAction" --> <result name="success" type="dispatcher">/WEB-INF/Hello.jsp</result> </action> <action name="test2" class="com.struts2.ActionTest.IndexAction6"> <result name="success" type="dispatcher">/WEB-INF/Hello.jsp</result> </action> <action name="test1" class="com.struts2.ActionTest.IndexAction5"> <result name="success" type="chain">test2</result> </action> <action name="tags" class="com.struts2.ActionTest.TagTest"> <result name="success" type="dispatcher">/WEB-INF/TagHello.jsp</result> </action> <!-- <default-action-ref name="hello_struts"></default-action-ref> 上面为默认跳转的action,若链接找不到,则调用上面的action--> </package></struts> web.xml:-->
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name>Struts2_test</display-name> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>