如何在jsp中获取上一个页面的完整URL
从一个jsp,通过一个链接,到另一个jsp;如何在下一个jsp中获取上个jsp的URL?
1.window.opener.location.href;
2.String url=request.getHeader("Referer");
3.传值的方法:
<input name="Submit" type="button" class="bn" value="347837" onClick="javascript:location.href='aaa.jsp?url=<%=request.getServletPath()%>'">
4.我的一个小例子,从url中获取html表单提交的用户名和密码。
下面的这个为test.jsp
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>log in</title>
</head>
<body>
<%
String url=request.getQueryString();
String [] test=url.split("&");
int n1=url.indexOf("name=",0);
int reg1=url.indexOf("&",n1);
String name=url.substring(n1,reg1);
int p1=url.indexOf("pwd=",0);
int reg2=url.indexOf("&",p1);
String pwd=url.substring(p1,reg2);
if(name.equals("name=good")&&pwd.equals("pwd=good"))
out.println("ok");
else
out.println("error");
%>
</body>
</html>
此为test.html,在此表单提交后期处理交由test.jsp来做
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>登录</title>
</head>
<body>
<form name="MAINFORM" method="get" action="test1.jsp">
<table align="center" border="1">
<tr>
<td><label>User Name</label></td>
<td><input name="name" type="text" size="12" maxlength="12" /></td>
</tr>
<tr>
<td><label>Password</label></td>
<td><input name="pwd" type="password" size="12" maxlength="12" /></td>
</tr>
<tr>
<td></td>
<!--<td width="20"><input name="OK" type="button" value="OK" onclick="test()"/></td>-->
<td width="20"><input name="OK" type="submit" value="登录"/></td>
</tr>
</table>
</form>
</body>
</html>