Issue in getting context path inside jsp?

浪尽此生 提交于 2019-12-12 10:44:10

问题


My jsp lies at below location

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

My image(accessed thru customer.jsp) lies at

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

In image tag i am making the absoulte path as below

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

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

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?


回答1:


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.

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




回答2:


Use ${pageContext.request.contextPath} instead



来源:https://stackoverflow.com/questions/12705193/issue-in-getting-context-path-inside-jsp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!