Hi.

We are using Oracle9i Application Server (which is more or less the same
engine as in Oracle 8.1.7 JServer). We use OSE in the appserver to deploy
servlets and jsp into the database.

A Jsp-page let's the user log in, and sets some login information in the
HttpSession of the client. The client then goes to a servlet which tries to
use the information set to the users session. This does not work :/ Somehow
the session doesn't exist.
HttpSession sess = request.getSession(false); returns null in the servlet.

I suppose this is because the jsp and the servlet doesn't share the same
SessionContext?

If I try the same thing in Tomcat 3.2 it works - the jsp and servlet can use
the same context.

I've also tried the same classes on J2EE-RI 1.2.1, and this server behaves
just like Oracles server - the jsp and servlet do not have access to the
same session.

Any ideas? I'm attaching the source-files for a simple jsp and servlet that
was used to test the above.

/Best Regards, Anders.

====================================
JSP
====================================
<%@ page contentType="text/html;charset=WINDOWS-1252"%>
<%@ page language = "java" import = "java.util.*" %>
<%@ page session="true"%>
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=WINDOWS-1252">
<META NAME="GENERATOR" CONTENT="Oracle JDeveloper">
<TITLE>
Hello World
</TITLE>
  <%
    //Kolla om vi har attribut som ska l�ggas till!
    String key = request.getParameter("key");
    String val = request.getParameter("val");
    if( (key != null) && (val != null) )
      session.setAttribute(key,val);
  %>
</HEAD>
<BODY>
  <H1>Attribut i sessionen:</H1>
  <%
        out.println("Cookie: " + session.getId());
        out.println("<P></P>");
    //Kolla igenom sessions.
    Enumeration objs = session.getAttributeNames();
    while( objs.hasMoreElements() ){
      String attName = (String)objs.nextElement();
      out.println( attName + " : " + session.getAttribute(attName) );
      out.println( "<BR>" );
    }
  %>
  <P>
    <!-- Foruml�r. -->
    <form action="sessJsp.jsp" method="POST">
      Key:&nbsp;<input type="text" name="key" value=""><BR>
      Value:&nbsp;<input type="text" name="val" value=""><BR>
      <input type="SUBMIT" name="sub" value="OK">
    </form>
  </P>
  <P>
    <!-- G� till servlet. -->
    <a href="/servlets/sessTest">Kolla servlet</a>
  </P>
</BODY>
</HTML>

====================================
Servlet
====================================
package test;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class SessionTest extends HttpServlet {

  /**
   * Initialize global variables
   */
  public void init(ServletConfig config) throws ServletException {
    super.init(config);
  }

  /**
   * Process the HTTP Get request
   */
  public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {

    //Kolla igenom cookies och sessioner etc.
    HttpSession sess = request.getSession();
    Enumeration enum = sess.getAttributeNames();
    StringBuffer buff = new StringBuffer();
    while( enum.hasMoreElements() ){
      String attName = (String)enum.nextElement();
      buff.append( attName + " : " + sess.getAttribute(attName) );
      buff.append( "<BR>" );
    }

    String ck = sess.getId();

    response.setContentType("text/html");
    OutputStreamWriter osw = new
OutputStreamWriter(response.getOutputStream());
    PrintWriter out = new PrintWriter (response.getOutputStream());
    out.println("<html>");
    out.println("<head><title>SessionTest</title></head>");
    out.println("<body>");
    out.println( "<H1>Cookie</H1>" );
    out.println( ck );
    out.println( "<H1>Attribut</H1>" );
    out.println( buff.toString() );
    out.println("</body></html>");
    out.close();
  }

  /**
   * Get Servlet information
   * @return java.lang.String
   */
  public String getServletInfo() {
    return "test.SessionTest Information";
  }
}

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to