I am poor at url rewriting and can not clearly understand its significance.
1) Please explain its significance.
2) give an example of redirecting jsp to servlet and using the parameters send attached to the url in the servlet class
3) I have seen a code where servlet2 is called from servlet1 as follows: res.sendRedirect("CallServlet?param1=value1¶m2=value"); but don't know how to read or use these values in servlet2
1. As HTTP protocol is stateless, so server has to use different technique to maintain conversational state between server and user. This conversational state is called "Session". There are two techniques which may be used by server to maintain session.
a. Cookie b. URL rewriting
In URL rewriting sever append session information in each URL send in the output page to browser. In case cookie is used, sever sends session data in cookie which is send back by browser with each subsequent request.
2. To send the request from one server resource to other server resource use
a.response.sendRedirect(new resource url) b.forward request (in jsp use <jsp:forward> c.include other resource (in jsp use <jsp:inlcude> or <%@include%>
3. request.getParameter(�param1�);
You should study the severlet/jsp basic concepts before asking question.
2 To send the request from one server resource to other server resource use I wanted to send some parameter along but getting error each time. Please help with code which shows parameters being send fom jsp and hence used in servlet
Originally posted by priya kakkar: Rahul I know what you have written is not url rewriting but I wanted to use same. Please help me by modifying my code to perform url rewriting
You can use session id it thats mandatory
I thought that you are interested to use getParameter method and get the value of the parameter from the url.Is this working ?
Check for encodeRedirectURL and encodeURL of HTTPServletResponse to make use of URL rewriting for session tracking.
The sessionId is not something you build yourself. The container takes care of that for you. Look at the methods that Raul posted earlier. Those methods do nothing more that add the (already existing) sessionID to your url.
None of this is even necessary if the user's browser has cookies enabled or is using SSL and has nothing to do with reading querystring variables.
Rather than trying to guess what these things do, you might want to consider downloading a copy of the servlet spec (link in my signature) and reading it. It won't take long and doing so will give you a real thorough understanding of concepts like this.
From servlet1 it is dispatched to servlet2 as following session.setAttribute("name","Priyanka"); response.encodeRedirectURL("/package1/Servlet3");
and from here to servlet3 where I want to read values from request assuming that since session is same so I can read values String str=(String)session.getAttribute("name");
But the control comes back to servlet1 after servlet2 instead of going to servlet3
How can i use urlrewriting and hence use value of attributes of session
priya, Please go back and re-read your last post. If there is a mistake in there, fix it so that it says what you really mean.
There are couple contradictions in there:
For Example:
From servlet1 it is dispatched to servlet2 as following session.setAttribute("name","Priyanka"); response.encodeRedirectURL("/package1/Servlet3");
And:
But the control comes back to servlet1 after servlet2 instead of going to servlet3
As mentioned earlier. The only thing URL Re-Writing does, is provide an alternate means of retaining the session ID for Browsers that do not allow cookies.
It doesn't directly involve passing request parameters. [ August 27, 2007: Message edited by: Ben Souther ]
The issue which you say contradictory is actually what is happening and is what is making me wonder
The problem now is that its going back to servlet1 and not going to servlet3 Please help by looking at my code and guide be by identifying where the code is wrong which make code to go back to servlt1 instead of going to servlet3
Please use real words when posting to the forums. Incorrect words such as "thankz" in place of "thanks" only serve to make your posts more difficult to read and less likely to generate useful responses.