Skip to content Skip to sidebar Skip to footer

How To Get Full Path Of Url Including Multiple Parameters In Jsp

Suppose URL: http:/localhost:9090/project1/url.jsp?id1=one&id2=two&id3=three <% String str=request.getRequestURL()+'?'+request.getQueryString(); System.out.println(st

Solution 1:

Given URL = http:/localhost:9090/project1/url.jsp?id1=one&id2=two&id3=three

request.getQueryString();

Should indeed return id1=one&id2=two&id3=three

See HttpServletRequest.getQueryString JavaDoc

I once face the same issue, It's probably due to the some testing procedure failure. If it happens, test in a clear environment : new browser window, etc.

Bhushan answer is not equivalent to getQueryString, as it decode parameters values !

Solution 2:

I think this is what you are looking for..

Stringstr=request.getRequestURL()+"?";
Enumeration<String> paramNames = request.getParameterNames();
while (paramNames.hasMoreElements())
{
    String paramName = paramNames.nextElement();
    String[] paramValues = request.getParameterValues(paramName);
    for (int i = 0; i < paramValues.length; i++) 
    {
        String paramValue = paramValues[i];
        str=str + paramName + "=" + paramValue;
    }
    str=str+"&";
}
System.out.println(str.substring(0,str.length()-1));    //remove the last character from String

Post a Comment for "How To Get Full Path Of Url Including Multiple Parameters In Jsp"