当前位置: 技术问答>java相关
有类似asp的 Request.ServerVariables("HTTP_REFERER") 的用法么?
来源: 互联网 发布时间:2015-10-22
本文导语: asp里 Request.ServerVariables("HTTP_REFERER") 用来得到链接到当前页的页面的URL,JSP里有这样的方法么? | 给你个servlet! import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; public...
asp里 Request.ServerVariables("HTTP_REFERER") 用来得到链接到当前页的页面的URL,JSP里有这样的方法么?
|
给你个servlet!
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class RequestHeaderExample extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Enumeration e = request.getHeaderNames();
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String value = request.getHeader(name);
out.println(name + " = " + value);
}
}
}
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class RequestHeaderExample extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Enumeration e = request.getHeaderNames();
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String value = request.getHeader(name);
out.println(name + " = " + value);
}
}
}