//通过request得到request的header的值 Enumeration e=request.getHeaderNames(); while(e.hasMoreElements()){ String key=(String)e.nextElement(); String value=(String)request.getHeader(key); } //防止盗链 String s=request.getHeader("referer"); if("http://www.javakc.com".equals(s)){ System.out.println("请求是从java快车的页面链接来的"); } //通过request取得Cookie Cookie[] cookies = request.getCookies(); for ( int i=0; i < cookies.length; i++ ) { String key =cookies[i].getName(); String value = cookies[i].getValue(); System.out.println("cook"+i+":key="+key+",value="+value); } //获取路径的方法对比, String s1=request.getContextPath(); String s2=request.getServletPath(); //获取uri String s3=request.getRequestURI(); //获取url StringBuffer sb=request.getRequestURL(); //服务器名称 String str=request.getServerName(); //获得"http" String http=request.getScheme(); //获取端口号 String port=request.getServerPort(); //设置HTTP头标 //5秒后自动刷新并转到http://..... response.setHeader("Refresh","5;URL=http://www.javakc.com"); //设置cookie Cookie c=new Cookie("cookieKey","cookieValue"); response.addCookie(c); //设定响应的content类型 response.setContentType("text/html"); response.setContentType("application/msword;charset=GB2312");