URL rewriting session management to achieve

2010-08-17  来源:本站原创  分类:Java  人气:188 

Originally posted address: http://www.javaeye.com/topic/620288

[Size = medium]
Typically, the session management server Session ID through a cookie stored on the user's Web browser to uniquely identify each user session. If your browser does not support cookies, or your browser is set to not accept cookies, URL rewriting can be achieved through the session management.

URL rewriting essentially connected by adding parameters to the URL and the session ID as the value contained in the connection. However, in order to make this effective, you need some of your servlet response to add to each connection session ID.

The session ID added to a connection can use a pair of methods to simplify: response.encodeURL () so that URL contains the session ID, if you need to use redirection, you can use response.encodeRedirectURL () to be encoded on the URL.

encodeURL () and encodeRedirectedURL () method first determine whether the browser supports cookies; if the support is to be stood return URL parameters, session ID cookies to maintain through.

Look at the following example, the two JSP files: hello1.jsp and hello2.jsp, and their impact between. We hello1.jsp in simple to create a session and stored in the session instance of an object. Then the user can click on the link page to reach hello2.jsp. In hello2.jsp, we get from the session object and display the original place its contents. Note that we call in hello1.jsp a encodeURL () method to get hello2.jsp links, making the browser to disable cookies in the case, session ID is automatically added to the URL, hello2.jsp able to get session object.

First of all, in the case of cookies enabled to run. Then turn off cookie support, restart the browser, run it again. Every time you can see the session management at work and can pass information between pages.

Note that if you want this case closed the cookies in the browser to work, your JSP engine must support URL rewriting.

hello1.jsp

<%@ page session="true" %>
<%
Integer num = new Integer(100);
session.putValue("num",num);
String url =response.encodeURL("hello2.jsp");
%>
<a href='<%=url%>'>hello2.jsp</a>  

<%@ page session="true" %>
<%
Integer num = new Integer(100);
session.putValue("num",num);
String url =response.encodeURL("hello2.jsp");
%>
<a href='<%=url%>'>hello2.jsp</a>

hello2.jsp

<%@ page session="true" %>
<%
Integer i= (Integer)session.getValue("num");
out.println("Num value in session is "+i.intValue());
%>  

<%@ page session="true" %>
<%
Integer i= (Integer)session.getValue("num");
out.println("Num value in session is "+i.intValue());
%>

Use, if your browser supports cookie, then, should be set to not support cookie, will be effective, you will see the link page address, sessionID value added.

response.sendRedirect(response.encodeURL(ABC));
response.sendRedirect(ABC);   

response.sendRedirect(response.encodeURL(ABC));
response.sendRedirect(ABC);

use response.sendRedirect (response.encodeURL (ABC)) The advantage is that he will make the user's session is appended to the URL at the end, that is, to ensure that users on different pages of the session object is the same.
The aim is to prevent some browsers do not support or session tracking is disabled COOKIE cause failure [/ size]

URL rewriting session management to achieve

相关文章
  • URL rewriting session management to achieve 2010-08-17

    Originally posted address: http://www.javaeye.com/topic/620288 [Size = medium] Typically, the session management server Session ID through a cookie stored on the user's Web browser to uniquely identify each user session. If your browser does not supp

  • URL rewriting to implement session management 2010-03-20

    Typically, the session management through the server Session ID as a cookie is stored in the user's Web browser to uniquely identify each user session. If the browser does not support cookies, or set your browser to not accept cookies, we can achieve

  • jstl c: rul URL url rewriting operation 2010-09-30

    URL action The rest of the JSTL core tag library is mainly on the URL. The first of these tags are properly named <c:url> tag, used to generate the URL. In particular, <c:url> provides three functional elements, they are constructed for the J2

  • Session, Cookie, jsessionid, and Url Rewriting 2010-11-29

    Session, Cookie, jsessionid, and Url Rewriting Fault Description: Personnel management system (A) embedded in the permissions system (B), B system through the Servlet simulated landing, and landing information cached in Session A system has to ensure

  • Session, Cookie, jsessionid, Url Rewriting 2010-12-02

    In some occasions, like voting, we often required because of the principle of fairness can only cast one vote per person, in a number of WEB development had a similar situation, we usually use this time to achieve COOKIE, such as the following code:

  • jsp to achieve URL rewriting with urlrewrite 2010-04-03

    jsp URL rewriting is achieved with urlrewrite URL of the site name to see other people do not compare with a cool name suffix, such as qq address space actually used urlrewrite this package is very easy to achieve. Here are instructions: 1. Download

  • Apache URL rewriting to achieve pseudo-static 2010-07-27

    1. Apache Settings Independent host user Apache basic configuration: First make sure you use the Apache version, and whether the module is loaded mod_Rewrite. Apache 1.x users, please check the conf / httpd.conf for the presence of the following two

  • IIS does not modify the transfer asp.netAsp.Net achieve URL rewriting, to support any extension and no extension 2010-11-14

    Speaking of not setting iis, mainly in order to achieve the operation of the virtual host or can not get iis limited time, you can not add isap want something similar to static program implementation, the first statement, where the final result to be

  • Java are three ways to achieve URL rewriting 2010-10-19

    URL rewriting, in fact, a lot of parameters to with the url, looks into the rules of a url, the main purpose is to search engines. Example / Viewthread.jsp? Id = 1234 / Viewthread.jsp? Id = 1235 / Viewthread.jsp? Id = 1236 Rewrite, you can use / View

  • wap development session management. 2010-06-13

    Phone side cookie, session, and URL rewriting purpose of this paper is to find out Session, Cookie, Url rewrite these concepts, and then elaborated on this basis, the use of Url rewriting in the development of Wap portal maintenance Session. What is

  • tomcat session management 2010-08-10

    Recently looked at tomcat 6 free Source inside of the session management implementation, is written down for later examination, but also hoping to interested friends Some tips. Gossip talk less, first posted about tomcat6 the component level diagram

  • October 19, 2010 database connection pool & URL rewriting 2010-10-19

    Feelings of deep learning day today. Am talking about the database connection pool. Very good topic. Is what I found when writing the project a solution to the problem. Access to the database, after all, have to face a problem. Use the database conne

  • At ajax use url rewriting them to avoid exposure url 2009-03-13

    I remember the first interview, questions have to do together Noodles: jsp page using ajax which required the implementation, when necessary java call the url; at this time the problem is that if users view the page source you can see is the url, how

  • Session Management in Hibernate 2009-05-22

    Session Management in Hibernate Session management in a variety of programs, ThreadLocal model has been widely used. ThreadLocal in Java are a more specific mechanism for thread binding. ThreadLocal access through the data, is always associated with

  • Hibernate Session Management on 2010-03-29

    On the Blog: http://blog.csdn.net/jhxck/ Session management options in the various, ThreadLocal pattern has been widely used. ThreadLocal is a Java thread in a more specific binding mechanism. ThreadLocal access through the data is always associated

  • [WebService Tutorial] Session (Session) Management - 5 2010-07-04

    WebService people feel is the most intuitive way from a one component, and the client through the SOAP protocol call these methods. These methods may have return values, may not return values. Although some tools that can be done, but the method is c

  • [WebService Tutorial] Cross-Service Session (Session) Management - 6 2010-07-04

    In the "WebService large auditorium of the Axis2 (5): Session (Session) Management" article describes how to use Axis2 to manage the session with a service, but a complex system, not only a WebService service, for example, at least there will be

  • URL rewriting class url class 2010-09-27

    Clean URL is a class that implements a method to make URLs more user and search engine friendly by removing '?' And '=' symbols from URI. This class is meant to be used in conjunction with URL rewriting Web server modules that map the cleaned URLs ge

  • struts2 + spring2.5 + hibernate3 + Extjs3 simple personnel management to achieve 2010-10-20

    struts2 + spring2.5 + hibernate3 + Extjs3 simple personnel management to achieve I am a beginner Extjs, many do not really understand, when you are doing with this small example, then be able to run up, but remove the modifications in the data will a

  • IIS does not modify the transfer asp.netAsp.Net URL rewriting implementation, support any extension and no extension 2010-11-14

    Speaking of not setting iis, mainly in order to achieve the operation of the virtual host or can not get iis limited time, you can not add isap want something similar to static program implementation, the first statement, where the final result to be