Results 1 to 4 of 4
Thread: Variables in a Servlet
- 06-09-2010, 09:54 AM #1
Member
- Join Date
- May 2010
- Posts
- 11
- Rep Power
- 0
Variables in a Servlet
Hi,
I'm using some variables in a servlet. the servlet response in a jsp page which after taking some more parameters gets redirected to another servlet. I want to use same variables I used in first servlet in the new one. How should i declare inorder to use this way. I know something like session attributes, but donno how to implement it. please help . please let me know the syntax.
Thanks
- 06-10-2010, 03:04 AM #2
the session is a property of the servlet request object.
in the first servlet,
where the value is any object.Java Code:public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.getSession().setAttribute("paramName", "some value"); }
in the second servlet
where you need to know the class type, usually by castingJava Code:public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Object val = request.getSession().getAttribute("paramName"); }
String value = (String) request.geSession().getAttribute("paramName");
- 06-10-2010, 02:10 PM #3
wouldn't
work also?Java Code:request.getParameter("paramName")
for the second servlet also work?:rolleyes: ~ Sno ~ :rolleyes:
'-~ B.S. Computer Science ~-'
- 06-11-2010, 02:20 AM #4
Yes, request.getParameter() would work on the second page, if the first page did a redirection thru a link on the page where there are URL parameters, or if there was a <form> element that was submitted.
If the first page is submitted back to itself and the server side does a HTTP 302 redirect, it might not have the URL parameters on the second page ?
Similar Threads
-
What are Instance variables and static variables?
By sandeshforu in forum New To JavaReplies: 3Last Post: 09-09-2009, 05:48 PM -
how can i link html+servlet+xml to form servlet
By balachandarr in forum Java ServletReplies: 0Last Post: 04-15-2009, 04:06 PM -
Servlet - apache tomcat/glassfish server shuts down on servlet usage
By StewS in forum Java ServletReplies: 1Last Post: 12-02-2008, 12:23 AM -
Is there any way to transfer the file Streams from one servlet to another servlet .
By HenaPriyadarsini in forum Java ServletReplies: 0Last Post: 08-30-2008, 11:52 AM -
javax.servlet.ServletException: Wrapper cannot find servlet class util.t2
By osval in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 03:47 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks