为什么无法访问请求中的属性? [英] Why can't access attribute in request?

查看:38
本文介绍了为什么无法访问请求中的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想访问请求中的一些属性,例如请求中的base属性,以下是请求中的部分值

I want to access some attributes in request, for example, the base attribute in request, the following are part of values in request

 request    ...base=/ecs, stack=com.opensymphony.xwork2.ognl.OgnlValueStack@11c4b31}, __cleanup_recursion_counter=1, .freemarker.RequestParameters=freemarker.ext.servlet.HttpRequestParametersHashModel@1c00cb4 ...

我使用 <s:debug/><s:property value="%{#request.base}"/>访问 request 中的 base 属性,但在我的 jsp 中没有显示.那为什么?

I use <s:debug /><s:property value="%{#request.base}" /> to access base attribute in request, but nothing shown in my jsp. So why?

推荐答案

不知道你为什么需要这个,但只有 baserequest 里面是在 .freemarker.TemplateModelScopesHashModel.所以你需要使用方法 get 从那里获取东西.

Not sure why do you need this but only base inside request is inside .freemarker.TemplateModel which is ScopesHashModel. So you need use method get to get things from there.

<s:property value="#request['.freemarker.TemplateModel'].get('base')" />

试试这个:

<s:property value="#request['javax.servlet.include.context_path']"/>

更新

如果你只需要上下文路径,那么使用 标签.

If you just need context path then use <s:url> tag for that.

<s:url value="/"/>

这篇关于为什么无法访问请求中的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆