Jsp request. getHeader usage

Source: Internet
Author: User
Tags http request session id server port stringbuffer

When the link is over, the referer value is the URL of the linked page, which is normal. When I refreshed the referer, the referer value was not changed, but when I press enter in the address bar (the URL is not changed, just press enter), the referer value became NULL.

1): is there any difference between the link and the URL entered in the address bar? If so, what is the difference?
2): Why is the URL unchanged during refresh? Why is the previous URL not changed to the current URL?
3): why cannot I directly enter the <% = request. getHeader ("REFERER") value?

If a page with a referer is directly input in the browser, the return value is null. That is to say, the referer will only have content when it comes to this page by clicking the link from another page. If it is NULL, it is manual. If it is not null, it is connected. During refresh, the server will check whether there are any updates. If there is no update, the local cache will be used. That is to say, the response you get during refresh is still

 

<% @ Page import = "java. util. *" %>
<Html>
<Head>
<Title> Echo </title>
<Style>
<Jsp Tutorial: include page = "style.css tutorial" flush = "true"/>
</Style>
</Head>
<Body>
<H1> HTTP Request Headers Received ed <Table border = "1" cellpadding = "4" cellspacing = "0">
<%
Enumeration eNames = request. getHeaderNames ();
While (eNames. hasMoreElements ()){
String name = (String) eNames. nextElement ();
String value = normalize (request. getHeader (name ));
%>
<Tr> <td> <% = name %> </td> <% = value %> </td> </tr>
<%
         }
%>
</Table>
</Body>
</Html>
<%!
Private String normalize (String value)
   {
StringBuffer sb = new StringBuffer ();
For (int I = 0; I <value. length (); I ++ ){
Char c = value. charAt (I );
Sb. append (c );
If (c = ';')
Sb. append ("<br> ");
      }
Return sb. toString ();
   }
%>


Integrated instance

Index. jsp
 
<HTML>
<HEAD>
<TITLE> Getting Header Data </TITLE>
</HEAD>
 
<BODY>
<H1> Getting Header Data </H1>
<Form action = "basic. jsp" METHOD = "POST">
<Input type = "submit" VALUE = "Submit">
</FORM>
</BODY>
</HTML>
 
Basic. jsp
 
<HTML>
<HEAD>
<TITLE> Reading Header Information </TITLE>
</HEAD>

<BODY>
<H1> Reading Header Information </H1>
Here are the request headers and their data:
<BR>
<% Java. util. Enumeration names = request. getHeaderNames ();
While (names. hasMoreElements ()){
String name = (String) names. nextElement ();
Out. println (name + ": <BR>" + request. getHeader (name) + "<BR> ");
        }
%>
</BODY>
</HTML>

The visitor's request. getHeader ("Referer") can be known through the method. Other methods are as follows:
System. out. println ("Protocol:" + request. getProtocol ());
System. out. println ("Scheme:" + request. getScheme ());
System. out. println ("Server Name:" + request. getServerName ());
System. out. println ("Server Port:" + request. getServerPort ());
System. out. println ("Protocol:" + request. getProtocol ());
System. out. println ("Server Info:" + getServletConfig (). getServletContext (). getServerInfo ());
System. out. println ("Remote Addr:" + request. getRemoteAddr ());
System. out. println ("Remote Host:" + request. getRemoteHost ());
System. out. println ("Character Encoding:" + request. getCharacterEncoding ());
System. out. println ("Content Length:" + request. getContentLength ());
System. out. println ("Content Type:" + request. getContentType ());
System. out. println ("Auth Type:" + request. getAuthType ());
System. out. println ("HTTP Method:" + request. getMethod ());
System. out. println ("Path Info:" + request. getPathInfo ());
System. out. println ("Path Trans:" + request. getPathTranslated ());
System. out. println ("Query String:" + request. getQueryString ());
System. out. println ("Remote User:" + request. getRemoteUser ());
System. out. println ("Session Id:" + request. getRequestedSessionId ());
System. out. println ("Request URI:" + request. getRequestURI ());
System. out. println ("Servlet Path:" + request. getServletPath ());
System. out. println ("Accept:" + request. getHeader ("Accept "));
System. out. println ("Host:" + request. getHeader ("Host "));
System. out. println ("Referer:" + request. getHeader ("Referer "));
System. out. println ("Accept-Language:" + request. getHeader ("Accept-Language "));
System. out. println ("Accept-Encoding:" + request. getHeader ("Accept-Encoding "));
System. out. println ("User-Agent:" + request. getHeader ("User-Agent "));
System. out. println ("Connection:" + request. getHeader ("Connection "));
System. out. println ("Cookie:" + request. getHeader ("Cookie "));
System. out. println ("Created:" + session. getCreationTime ());
System. out. println ("LastAccessed:" + session. getLastAccessedTime ());

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.