lat*_*ata 4 javascript url jsp uri
假设
URL: http:/ localhost:9090/project1/url.jsp?id1 = 1&id2 = 2&id3 = 3
<%
String str=request.getRequestURL()+"?"+request.getQueryString();
System.out.println(str);
%>
Run Code Online (Sandbox Code Playgroud)
有了这个,我得到输出 http:/ localhost:9090/project1/url.jsp?id1 = 1
但有了这个,我只能检索第一个参数(即id1 = 1)而不是其他参数
但如果我使用javascript我能够检索所有参数
function a()
{
$('.result').html('current url is : '+window.location.href );
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<div class="result"></div>
Run Code Online (Sandbox Code Playgroud)
我想检索要在我的下一页中使用的当前URL值,但我不想使用会话
使用以上两种方法中的任何一种如何检索jsp中的所有参数?
提前致谢
给定URL = http:/ localhost:9090/project1/url.jsp?id1 = 1&id2 = 2&id3 = 3
request.getQueryString();
Run Code Online (Sandbox Code Playgroud)
应该确实返回id1 = 1&id2 = 2&id3 = 3
请参阅HttpServletRequest.getQueryString JavaDoc
我曾经面临同样的问题,这可能是由于某些测试程序失败了.如果发生这种情况,请在清晰的环境中进行测试:新浏览器窗口等.
Bhushan的答案不等同于getQueryString,因为它解码参数值!
我想这就是你要找的..
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23330 次 |
| 最近记录: |