Get the URL from mJSP page

2019-04-06 08:33发布

I would grab the URL of the current JSP web page with its settings example: index.jsp? param = 12

Have you any idea? Thank you

标签: jsp url
2条回答
Luminary・发光体
2楼-- · 2019-04-06 09:08

You can get it from the HttpServletRequest object which is in EL available by ${pageContext.request}. The part before the ? is available by getRequestURL() method and the part after the ? is available by getQueryString() method. So, in a nutshell:

<p>Request URL: ${pageContext.request.requestURL}</p>
<p>Query string: ${pageContext.request.queryString}</p>
<p>Full URL: ${pageContext.request.requestURL}?${pageContext.request.queryString}</p>

If you want to do this using normal Java code, you'd better use a Servlet for this.

String requestURL = request.getRequestURL().toString();
String queryString = request.getQueryString();
if (queryString != null) requestURL += "?" + queryString;
// ...
查看更多
叼着烟拽天下
3楼-- · 2019-04-06 09:14

Look at the HttpServletRequest Object, which you can access from your JSP in a scriplet (although that's not pretty). It has many methods for getting the URL of the page, including the parameters. Methods of interest will be:

 - getQueryString 
 - getRequestURI
 - getRequestURL

Have a play with them.

查看更多
登录 后发表回答