Get the URL from mJSP page

后端 未结 2 1618
情话喂你
情话喂你 2021-02-20 18:49

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

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-20 19:18

    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:

    Request URL: ${pageContext.request.requestURL}

    Query string: ${pageContext.request.queryString}

    Full URL: ${pageContext.request.requestURL}?${pageContext.request.queryString}

    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;
    // ...
    

提交回复
热议问题