If this is in a JSP page, you don't need to get the session from the
request. Go to the java.sun.com site, select APIs, select Java Server Pages
and print yourself out the JSP Syntax Card. It tells you what you can use in
JSP. There is a session variable already defined for you. Also, there is a
servlet context variable (application scope), and others as well.


As for why one page is getting some HTML from the previous..it has nothing
to do with your session use. That is just a Hashtable of objects stored by a
key name. I don't remember for sure, but it has something to do with the way
pages are being flushed. If you forward from one page to the next, you
continue to build upon the html that goes back to the client. When you
response.sendRedirect(), my guess is that the buffer is not completely
flushed or something. I believe the JSP Syntax Card has an item that you can
set at the top of a JSP page that flushes the buffer. Look for that and see
if that helps. May I also suggest you use a simple MVC framework? If your
using Servlet 2.1 I have made one that makes it very easy to develop with.
Struts is another very good MVC framework more complete than my own.

Let me know if you are interested in that approach, which will resolve this
for you but require a bit different approach in coding (one that thus far
most people believe is a better more manageable and more scalable approach
than calling JSPs from other JSPs).



-----Original Message-----
From: Øystein Walle
To: Orion-Interest
Sent: 2/12/2001 4:46 AM
Subject: Using Session Variables

Hi.
 
I'm having some difficulty using session variables. Here's a short
abridgement of my code in evaluate.jsp:
 
HttpSession thisSession = request.getSession(true);
...
while(enum.hasMoreElements()){
    intValue = fncFunction(...);
    switch(value){
        case -1:
            thisSession.putValue("errorMsg","Error in
fncFunction()....");
 
response.sendRedirect(response.encodeRedirectURL("../errorpages/error.js
p"));
            break;
        case -2:
        ...
    }
}
 
The problem: the error.jsp page sometimes shows some of the HTML code in
the evaluate.jsp page.
The error.jsp page looks something like this:
 
HttpSession thisSession = request.getSession(true);
 
String strError=(String)thisSession.getValue("errorMsg");
if (strError!=null && strError!="")
     out.println(strError);
else
     out.println("Ingen nærmere feilbeskjed er tilgjengelig.<br>");
 
What's the problem here?? It seems to me that the session variable
includes much more than my simple errorMsg.
 
Øystein
 

Reply via email to