使用${requestScope['javax.servlet.forward.servlet_path']}<我可以从我的URL..say中获得适当的值,例如
如果我有URL http://localhost:8080/myapp/request1,我可以在${requestScope['javax.servlet.forward.servlet_path']}的帮助下获得/myapp/request1,但是在某些情况下,URL可能会附加一些查询字符串,如http://localhost:8080/myapp/request1?text=abc
在这种情况下,我想要包含查询字符串/myapp/request1?text=abc的URL,我试图使用${requestScope['javax.servlet.forward.query_string']},但它是空的。
有人能帮我理解一下${requestScope['javax.servlet.forward.query_string']}在哪里可以是空的吗?或处理上述两种情况的最佳方法是什么?
发布于 2014-02-11 01:20:38
要获得附加了查询字符串的上下文相对路径,请使用筛选器或前端控制器servlet中的以下代码:
contextRelativePath = request.getRequestURI().substring(
request.getContextPath().length()).toLowerCase().trim();
String queryString = request.getQueryString();
if(queryString != null){
contextRelativePath += queryString;
}
request.setAttribute("path", contextRelativePath);现在,您可以从JSP访问路径,如${ path }中所示
https://stackoverflow.com/questions/21683021
复制相似问题