JSP - Servlet - Session problem

W

wawa_piggy

I have a JSP page which will post to a servlet upon clicking the
"submit" button.

The servlet will perform some processing and then redirect back to the
JSP with all the original form fields prefilled.
Which means i need to have a means for "transferring" a fair amount of
data values from JSP to servlet back to JSP
so i cannot append the data as querystring behind my Url when i do a
response.sendRedirect() from my servlet to JSP.

In my servlet, i have the below code. I try to set the values into a
session before i use a response.sendRedirect() to
direct back to the JSP. But in the JSP, i don't seems to be able to
retrieve back the session values
that i have set in the servlet.


public void service ( HttpServletRequest request, HttpServletResponse
response )
throws ServletException, IOException
{
:
: // processing code
:

HttpSession session = request.getSession(false);
session.setAttribute("empID","TUU565");
:
:

response.sendRedirect(strEncodeUrl);


} // end of service() method


I am using SUNONE server. I need a way to pass values from the servlet
back to JSP.
What am I doing wrong? Or is there any other methods ??

Thank you very much.
 
T

Tony Morris

wawa_piggy said:
I have a JSP page which will post to a servlet upon clicking the
"submit" button.

The servlet will perform some processing and then redirect back to the
JSP with all the original form fields prefilled.
Which means i need to have a means for "transferring" a fair amount of
data values from JSP to servlet back to JSP
so i cannot append the data as querystring behind my Url when i do a
response.sendRedirect() from my servlet to JSP.

In my servlet, i have the below code. I try to set the values into a
session before i use a response.sendRedirect() to
direct back to the JSP. But in the JSP, i don't seems to be able to
retrieve back the session values
that i have set in the servlet.


public void service ( HttpServletRequest request, HttpServletResponse
response )
throws ServletException, IOException
{
:
: // processing code
:

HttpSession session = request.getSession(false);
session.setAttribute("empID","TUU565");
:
:

response.sendRedirect(strEncodeUrl);


} // end of service() method


I am using SUNONE server. I need a way to pass values from the servlet
back to JSP.
What am I doing wrong? Or is there any other methods ??

Thank you very much.

Perform a server-side redirect, rather than a HTTP 302 redirect, using a
requestDispatcher.
Also,
HttpSession session = request.getSession(false);
'session' may be null after this call, so make sure you check before
dereferencing it.

--
Tony Morris
(BInfTech, Cert 3 I.T.)
Software Engineer
(2003 VTR1000F)
Sun Certified Programmer for the Java 2 Platform (1.4)
Sun Certified Developer for the Java 2 Platform
 
H

hiwa

I have a JSP page which will post to a servlet upon clicking the
"submit" button.

The servlet will perform some processing and then redirect back to the
JSP with all the original form fields prefilled.
Which means i need to have a means for "transferring" a fair amount of
data values from JSP to servlet back to JSP
so i cannot append the data as querystring behind my Url when i do a
response.sendRedirect() from my servlet to JSP.

In my servlet, i have the below code. I try to set the values into a
session before i use a response.sendRedirect() to
direct back to the JSP. But in the JSP, i don't seems to be able to
retrieve back the session values
that i have set in the servlet.


public void service ( HttpServletRequest request, HttpServletResponse
response )
throws ServletException, IOException
{
:
: // processing code
:

HttpSession session = request.getSession(false);
session.setAttribute("empID","TUU565");
:
:

response.sendRedirect(strEncodeUrl);


} // end of service() method


I am using SUNONE server. I need a way to pass values from the servlet
back to JSP.
What am I doing wrong? Or is there any other methods ??

Thank you very much.

Why getSession(false), not (true)?
Why strEncodeUrl, not encodeRedirectURL()?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top