How to get the full URL path including several parameters in jsp

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

<% String str=request.getRequestURL()+"?"+request.getQueryString(); System.out.println(str); %> 

with this i get the output http: / local: 9090 / project1 / url.jsp id1 = one

but with this I can only get the 1st parameter (i.e. id1 = one) and not the other parameters


but if i use javascript i can get all parameters

 function a() { $('.result').html('current url is : '+window.location.href ); } 

HTML:

 <div class="result"></div> 

I want to get the current URL value that will be used on my next page, but I do not want to use sessions

using either of the two methods above, how to get all parameters in jsp?

early

+4
source share
2 answers

I think this is what you are looking for.

 String str=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 
+4
source

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

 request.getQueryString(); 

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

See HttpServletRequest.getQueryString JavaDoc

I am facing the same problem, possibly due to a failed testing procedure. If this happens, check in a clean environment: a new browser window, etc.

Bhushan's answer is not equivalent to getQueryString as it decodes parameter values!

+6
source

All Articles