📄 req_headers.xtp
字号:
<s1 title="Headers"><p>Sophisticated servlets can use browser headers to tailor the returned pageto the browser. For example, a high-quality site can detect a Palm Pilotbrowser and simplify its site design to match the browser capabilities.</p><p>Each browser request sends <var/headers/> along with the URL. Theheaders include the browser type (<var/User-Agent/>) andlanguage preferences (<var/Accept-Language/> and <var/Accept-Charset/>). Thefull list is in the official HTTP/1.1 spec, but those three are the mostimportant.</p><p>Servlet and JSPs grab headers with <var/request.getHeader/>.</p><p>The following, like env.jsp in the examples, gets all the headersand prints them. Little "snoop" servlets like this are useful to see whatheaders browsers are sending.</p><example title="test.HeaderServlet.java">package test;import java.io.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;public class HeaderServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); out.println("<table>"); Enumeration e = request.getHeaderNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); out.println("<tr><td>" + name); out.println("<td>" + request.getHeader(name)); } out.println("</table>"); }}</example><results>Connection Keep-Alive User-Agent Mozilla/4.74 [en] (X11; U; Linux 2.4.0-test1 i686) Host localhost:8080 Accept image/gif, image/jpeg, image/pjpeg, image/png, */* Accept-Encoding gzip Accept-Language en Accept-Charset iso-8859-1,*,utf-8 Cookie JSESSIONID=7tXlVCaALedCHHkdXy </results></s1>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -