//修改.action后缀 <constant name="struts.action.extension" value="html"></constant>
默认没有配置后缀,其实不添加.acton后缀也可以访问
//web.xml也可以配置修改后缀 <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>do</param-value> </init-param> </filter>
struts.properties的常用配置
加后缀访问,如.html,http://localhost:8080/HelloWord/helloWord.html
配置方式如下:
<!-- 访问的后缀发生变化
value="html"时,访问的后缀就是hello_add.html
value的值为空时,访问就可以不加后缀 (不写这句话时也可以不加后缀名的访问)-->
方式一:写在struts.xml <constant ame="struts.action.extension" value="html"></constant>
方式二:写在properties定义属性里
struts.action.extension=action,do
方式三:在web.xml中的struts2过滤器中初始化参数
<init-param
>
<
param-name
>struts.action.extension</
param-name
>
<
param-value
>do</
param-value
>
</
init-param
>
1、多个配置文件可以用<include>,在struts.xml中统一配置
<include file="xx.xml"></include>
2、设置常量(此方法可以顶替struts.properties文件)
<constant name="常量名" value="常量值"></constant>
3、动态方法调用+通配符使用
<action name="*_*" method="{2}" class="包全名.{1}"> <!-- *_*中*代表任意字符,_代表固定格式 {1}{2}是第几个*所代表的字符串 例:hello_add {1}=hello【action名】;{2}=add【action中方法名】 调用hello.acton中的add() --> <result>/xx.jsp</result> </action>
4、默认action(用来处理找不到相应action时,统一跳到一个友好界面)
<default-action-ref name="aaa"></default-action-ref> <action name="aaa"> <result>/xx.jsp</result> </action>
注:当同包中存在action name="*_*"时,访问路径写成hello_aaa不能跳到指定的目标。用为会默认先匹配action部分,匹配成功后就不再找默认action了。
5、struts2后缀
<!-- struts.xml中添加常量修改action后缀 --> <constant name="struts.action.extension" value="html"></constant> <!-- 1、后缀再写action报错,要改成.html 2、该常量也可以在struts.properties中配置 struts.action.extension=action,do,struts2 3、也可以在过滤器<filter>中配置 <init-param> <param-name>struts.action.extension</param-name> <param-value>do</param-value> </init-param> -->
struts.properties
通过修改 extension 属性 将可用的struts后缀进行修改
即可使用 .do .json 访问action
@Struts2---编写struts2后缀的三种方式
方式一:在struts.xml中设置
<constant name="struts.action.extension" value="do"></constant>
方式二:在struts.properties中设置
struts.action.extension=action,do
方式三:在web.xml中的struts2过滤器中初始化参数
<init-param> <param-name>struts.action.extension</param-name> <param-value>do</param-value> </init-param>
struts2后缀: 三种方式: 1.struts.properties中:struts.action.extension=action,do,struts2 2.xml中增加常量constant: <constant name="struts.action.extension" value="action,do,struts2"></constant> 3.在过滤器中配置intt-param参数: <init-param> <param-name>struts.action.extension</param-name> <param-value>do,action,strtus2</param-value> </init-param>
三种方式 可以定制 url的后缀:
在struts.xml的包外面配置常量<constant name="struts.action.extension" value="指定扩展名"></constant>
在struts.propertios文件中配置struts.action.extension=指定的扩展名1,指定扩展名2,。。。(以 逗号隔开 可以配置多个后缀名 )
在web.xml中配置strutsPreparedAndExecuteFilter时初始参数配置<init-param><param-name>struts.action.extension</param-name><param-value>指定扩展名</param-value></init-param>
可在3处地方配置后缀
url后缀的定制:
在struts.xml的包外面配置常量<constant name="struts.action.extension" value="指定扩展名"></constant>
在struts.propertios文件中配置struts.action.extension=指定的扩展名1,指定扩展名2,。。。(可以配置多个)
在web.xml中配置strutsPreparedAndExecuteFilter时初始参数配置<init-param><param-name>struts.action.extension</param-name><param-value>指定扩展名</param-value></init-param>