<%@page language="java" contentType="text/html;charset=utf-8" session="false"%>
<jsp:forward page="page2.jsp"/><%@page language="java" contentType="text/html;charset=utf-8" session="false"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>page2</title>
</head>
<body>
<%
out.println("getRequestURI():"+request.getRequestURI()+"<br/>");
out.println("getRequestURL():"+request.getRequestURL()+"<br/>");
out.println("getServletPath():"+request.getServletPath()+"<br/>");
%>
</body></html>地址栏显示page1.jsp;如何获取到这个“page1.jsp”的字母串
public String getFullURL(HttpServletRequest request) {
StringBuffer url = request.getRequestURL();
if (request.getQueryString() != null) {
url.append('?');
url.append(request.getQueryString());
}
return url.toString();
}
<html>
<head>
<title>
index
</title>
</head>
<body bgcolor="#ffffff">
<%
response.sendRedirect("跳转页面");
%>
</body>
</html>
另外我需要在page2.jsp中的java代码片段中使用“浏览器地址栏的URL”,所以不可能在java代码的执行过程中使用JavaScript。
这个我在项目中使用过的。能够正常取出request的URL。你DEBUG一下找找原因吧。
其实我提的问题的关键在于
request.getRequestURL()和浏览器地址栏的的URL不匹配。浏览器地址栏显示http://localhost:8080/page1.jsp,
request.getRequestURL()得到的却是"http://localhost:8080/page1.jsp"
request.getRequestURL()得到的却是"http://localhost:8080/page2.jsp"
浏览器地址栏显示http://localhost:8080/page1.jsp,
request.getRequestURL()得到的却是"http://localhost:8080/page2.jsp"