Sturts2中action向jsp页面传值

*** 赋值方式

1.实现ServletContextAware, ServletRequestAware, ServletResponseAware 接口
例:
	@Override
	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
	}
	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
		this.session = request.getSession();
	}
	@Override
	public void setServletContext(ServletContext application) {
		this.application = application;
	}



2.通过ActionContext获取Map类型的ServletAPI (与上面的类型不同,但数据相同)
	ActionContext context = ActionContext.getContext();
	Map<String,Object> session=context.getSession();
	Map<String,Object> application=context.getApplication();


3.使用ActionContext直接保存数据:
	ActionContext context = ActionContext.getContext();
	context.put("key", "value");



*** 在JSP中访问
key为键值:
HttpServletRequest request中保存的数据
Property 具有getter方法的成员
ActionContext ActionContext中直接保存的数据
HttpServletSession session中保存的数据
ServletContext application中保存的数据
按优先级(搜索key的顺序)先后排列:

	${key}
			// HttpServletRequest > Property > ActionContext > HttpServletSession > ServletContext


	${sessionScope.key}
			// HttpServletSession


	${session.key}
			// HttpServletSession


	${application.key} 
			// ServletContext


	<s:property value="key"/> 
			// Property > ActionContext


	<s:property value="#key"/> 
			// ActionContext


	<s:property value="#request.key"/> 
			HttpServletRequest > Property > ActionContext


	<s:property value="#session.key"/> 
			HttpServletSession


	<s:property value="#application.key"/> 
			ServletContext

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值