在jsp中获取上下文路径的问题? [英] Issue in getting context path inside jsp?

查看:254
本文介绍了在jsp中获取上下文路径的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的jsp位于以下位置

My jsp lies at below location

http://myApp.com/myWebApp/customer/images/customer.jsp

我的图片(通过customer.jsp访问)位于

My image(accessed thru customer.jsp) lies at

http://myApp.com/myWebApp/images/customer.gif

在图片标签中,我的absoulte路径如下所示

In image tag i am making the absoulte path as below

src="${param.contextPath}images/customer.gif"

仅供参考在这里使用param这是我们在EL中访问请求参数的方法。

just for info i am using param here becoz this is how we access request params in EL.

我原以为$ {param.contextPath}会返回/ myWebApp /但是它正在返回/ myWebApp /顾客/。 有没有办法可以获得
上下文路径(不是客户名称空间),即/ myWebApp / from request?

I was expecting that ${param.contextPath} will return /myWebApp/ but it is returning /myWebApp/customer/. Is there a way i can get just context path(not with customer namespace) i.e /myWebApp/ from request?

推荐答案

如果从请求参数中读取上下文路径,则某人必须事先使用某个值填充它。这个值是不正确的,因为没有关于谁填充这个值的信息以及如何,关于它的说法不多。

If you read the context path from a request parameter, then someone must have populated it beforehand with some value. That value was incorrect, and as there is no information as to who populated this value and how, not much can be said about it.

尝试使用 $ {pageContext.request.contextPath} 。这是获取部署应用程序的上下文路径的标准方法。

Try using ${pageContext.request.contextPath} instead. That is the standard method to obtain the context path under which your application is deployed.

这篇关于在jsp中获取上下文路径的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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