Struts2 为Action 的属性注入值&& 处理请求后缀

在Struts2中的配置文件中,我们可以很方面的为Action中的属性注入值。注意:属性必须提供set()若在页面中显示 必须提供get()

<action name="list" class="cn.itcast.action.UserAction" method="execute">
			<param name="savepath">/strutsDemo</param>
			<result name="success">/employee.jsp?username=${username}
                        </result>
</action>

 若对某action进行访问,默认使用.action后缀访问Action。其实默认后缀是可以通过常量“struts.action.extension”进行修改  我们可以配置Struts2只处理以.do为后缀的请求路径

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.action.extension" value="do"/>
</struts>

 

如果用户需要指定多个请求后缀 ,则多个后缀之间以英文逗号【,】
隔开

<constant name="struts.action.extension" value="do,go"/>

 常量可以在struts.xml或struts.properties中配置,建议在struts.xml中配置,两证配置方式如下:
<struts>
<constant name="struts.action.extension" value="do,go,action"/>
<struts>

在struts.properties中配置常量
struts.action.extension=do

转载于:https://www.cnblogs.com/lomomiao/p/4161833.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值