Struts2的常见配置

配置文件的加载顺序

1.struts.xml

2.struts.properties

3.web.xml

ps:后配置的会覆盖前边的(如果重复)

package相关配置

package标签称为包,这个包与Java中的包的概念不一致。包为了更好管理action的配置。
package标签的属性:
name        :包的名称,只有在一个项目中不重名即可。
extends        :继承哪个包,通常值为struts-default。
namespace    :名称空间,与<action>标签中的name属性共同决定访问路径。
                 名称空间有三种写法:(优先级:查找顺序从上往下)
                       带名称的名称空间        :namespace=”/ss” 
                       跟名称空间            :namespance=”/”
                       默认名称空间            :namespace=””
abstract        :抽象的,用于被其他包继承。

action相关配置

action标签配置Action类。
       action标签的属性
       * name        :与namespace共同决定访问路径
       * class            :Action类的全路径(带包名)
       * method        :执行Action中的哪个方法的方法名,默认值execute
      converter        :用于设置类型转换器

Struts2的常量配置

在Struts2的框架中,提供了非常多的常量:(在default.properties)
       struts.i18n.encoding=UTF-8            ----Struts2中所有的post请求的中文乱码不用处理。
       struts.action.extension=action,,        ----Struts2请求的默认的扩展名。默认扩展名是.action或者什么都不写。
在Struts2中修改一些常量的值:
       修改常量的值,可以有三个位置进行修正
       struts.xml中进行修改(常用)

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
	"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
	<!-- 配置Struts2的常量 -->
	<constant name="struts.action.extension" value="action"></constant>
	
	<!-- Struts2为了管理Action的配置,通过包进行管理 -->
	<!-- 配置Struts2的包============== -->
	<package name="demo1" extends="struts-default" namespace="/">
		<!-- 配置Action============= -->
		<action name="hello" class="com.struts.demo1.HelloAction">
			<!-- 配置页面的跳转========== -->
			<result name="success">/demo1/success.jsp</result>
		</action>
	</package>
</struts>

struts.properties中进行修改

struts.action.extension=action

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_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>struts_day01</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <!-- 配置Struts2的核心过滤器 -->
  <filter>
  	<filter-name>struts2</filter-name>
  	<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  	<!-- 修改常量 -->
  	<init-param>
  		<param-name>struts.action.extension</param-name>
  		<param-value>ss</param-value>
  	</init-param>
  </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、付费专栏及课程。

余额充值