Loading
 
What's Next: View All Tutorial →

Get Address bar Url with query string from JSP

Get Address bar Url with query string from JSP Example 1: <% String addressBarUrl = ""; // using getAttribute allows us to get the orginal url out of the page when a forward has taken place. String queryStringParam =...

Published Date: 22/10/2014  Last Modified Date: 22/10/2014    New Post



Get Address bar Url with query string from JSP

Example 1:
<%
    String addressBarUrl = "";
    // using getAttribute allows us to get the orginal url out of the page when a forward has taken place.
    String queryStringParam = "?" + request.getAttribute("javax.servlet.forward.query_string");
    String requestURI = "" + request.getAttribute("javax.servlet.forward.request_uri");
    if (requestURI == "null") {
        // using getAttribute allows us to get the orginal url out of the page when a include has taken place.
        queryStringParam = "?" + request.getAttribute("javax.servlet.include.query_string");
        requestURI = "" + request.getAttribute("javax.servlet.include.request_uri");
    }
    if (requestURI == "null") {
        queryStringParam = "?" + request.getQueryString();
        requestURI = request.getRequestURI();
    }
    if (queryStringParam.equals("?null")) {
        queryStringParam = "";
    }
    addressBarUrl = requestURI + queryStringParam;
    out.println(addressBarUrl);
%>

Example 2:
 

<%
 String scheme = request.getScheme();
    String serverName = request.getServerName();
    int serverPort = request.getServerPort();
    String uridata = (String) request.getAttribute("javax.servlet.forward.request_uri");
    String paramstr = (String) request.getAttribute("javax.servlet.forward.query_string");
    String referalUrl = scheme + "://" + serverName + ":" + serverPort + uridata + "?" + paramstr;
    out.println(referalUrl);
    session.setAttribute("referalUrl", referalUrl);

%>
Awaiting for Administrator approval




← Back to list


Related Post




×