如何获取URL的完整路径,包括jsp中的多个参数 [英] how to get full path of URL including multiple parameters in jsp

查看:304
本文介绍了如何获取URL的完整路径,包括jsp中的多个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设
URL : http:/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),而不能检索其他参数

but with this i am able to retrieve only 1st parameter(i.e id1=one) not other parameters


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


but if i use javascript i am able to retrieve all parameters

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

html:

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

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

i want to retrieve current URL value to be used in my next page but i don't want to use sessions

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

using any of above two method how do i retrieve all parameters in jsp?

预先感谢

推荐答案

我认为这就是您想要的..

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

这篇关于如何获取URL的完整路径,包括jsp中的多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆