小编典典

如何获取包含jsp中多个参数的URL的完整路径

jsp

假设
URLhttp:/ localhost:9090 / project1 / url.jsp?id1 = one&id2 = two&id3
= three

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

这样我得到输出 http:/ localhost:9090 / project1 / url.jsp?id1 = one

但是有了这个,我只能检索第一个参数(即id1 = one),而不能检索其他参数

但是,如果我使用javascript,我就能检索所有参数

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

的HTML:

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

我想检索要在下一页中使用的当前URL值,但我不想使用会话

使用以上两种方法中的任何一种,如何在jsp中检索所有参数?

提前致谢


阅读 485

收藏
2020-06-10

共1个答案

小编典典

我想这就是您要寻找的..

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
2020-06-10