从mJSP页面获取URL [英] Get the URL from mJSP page
本文介绍了从mJSP页面获取URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将使用其设置获取当前JSP网页的URL 例如:index.jsp?参数= 12
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
推荐答案
您可以从 EL 中的HttpServletRequest.html"rel =" noreferrer> HttpServletRequest
对象>. ?
之前的部分可通过 getRequestURL()
方法和?
之后的部分可通过
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>
如果要使用普通的Java代码执行此操作,则最好为此使用 Servlet .
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;
// ...
这篇关于从mJSP页面获取URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文