struts2-struts2的基本配置

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>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值