Posts Tagged ‘url rewriting’

Define URL Rewriting Frequently Asked Interview Question Answers

What Is URL Rewriting

 

As we know that session needs to be maintained because http is a stateless protocol.Due to which connection is lost or session is lost after every request response cycle between the client and the server.In order to maintain or track the session the server needs to get the additional information of the session id so that the session object pertaining to the client or server can be retrieved at the server side and the session can be managed.The session can be managed by either  cookies,hidden parameter or URL rewriting.

URL Rewriting is used in the cases where client browser does not accept cookies.In such case the server does not get the session id thus it is unable to relate he session object with the client or user.In order to maintain the session some extra piece of code needs to be added so that even if the cookies are not accepted at the browser level still the session can be maintained.URL Rewriting is something to fall upon as a precautionary measure.The code to get session and URL Rewriting is demonstrated below :

request.getSession();
out.println("<a href = "\"+response.encodeURL()+""\>Click Here</a>");

Here the anchor tag is used for URL Rewriting.Since the extra measure is used to take care that if the client browser does not accept cookies the session id is attached to the URL so that the session can be maintained.In URL Rewriting the session id is passed as an extra information with the URL that means rewriting of the URL is done.URL Rewriting can also be done with redirection as below :

response.sendRedirect(response.encodeRedirectURL("URL-Pattern of the servlet"));

The first time the server  tries with both cookies and URL Rewriting ,if it finds that the cookies are not coming it checks for session id as a part of URL Rewriting and finds that it has to fall upon URL Rewriting if the code has provisioned that.

 

Number of View :2120

Tags: , , , , , , , , ,

No Comments


Concept Of Session In J2EE Session Tracking In J2EE Session Management Seesion Concept Servlet Basics Servlet Guide Session Tracking

Sessions In J2EE(How to maintain session in java web applications)

Session in J2EE application is the time of interaction between the client and the server.A session in used to retain the state of a client.As we know that http is connectionless protocol,after each request and response cycle between the client and the server,the connection is broken. It seems logical to break the connection as bandwidth is an expensive resource and needs to be relinquished so that the same can be used for another request.This is the reason http is the protocol used to access the web application in any web technology.

With the advantage of releasing the bandwidth comes the issue of maintaining the session in J2EE ,as after the request response cycle,the server does not remember the client.

So some extra work is needed in order to maintain the session.

The code to get a session object in servlet is as follows :

request.getSession(TRUE);

or

request.getSession(FALSE);

 

The difference between the two overloaded functions is that the function with ‘ TRUE’ as parameter returns a new session object even if a session does not  exist otherwise it will return the preexisting session object but in the later case the function will return the existing session object if it exists or if not existing a null  will be returned.

As we have got the session in a servlet now,it will be lost after a request response cycle.So,in order to maintain session we need to follow either of the approaches from:

1. Hidden parameters

2. Cookies

3. URL rewriting

1. Hidden parameter : In this case we pass the session id allotted by the server to the session object via parameters

2. Cookies : In this case the browser downloads the cookies at the client side,so that it can append the session id with each request.Creating a cookie ,attaching session id to it and sending it to the client side is all done implicitly by the server as soon as we execute the code

request.getSession(TRUE/FALSE);

 

3. URL rewriting is something to fall upon if the browser at the client side doe snot accept cookies.In such cases we encode the URL with an extra info called sessionid as the parameter.

The code for url rewriting is as follows :

response.encodeRedirectUrl("url-pattern");

 

Number of View :1935

Tags: , , , , , , , ,

No Comments



SetPageWidth
Content Protected Using Blog Protector By: PcDrome.

Mahol Dot Org is Stephen Fry proof thanks to caching by WP Super Cache