tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 24496] New: - could not retrive httpsession
Date Fri, 07 Nov 2003 14:42:38 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=24496>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=24496

could not retrive httpsession

           Summary: could not retrive httpsession
           Product: Tomcat 4
           Version: 4.1.24
          Platform: PC
        OS/Version: Linux
            Status: UNCONFIRMED
          Severity: Critical
          Priority: Other
         Component: Servlet & JSP API
        AssignedTo: tomcat-dev@jakarta.apache.org
        ReportedBy: rony@groupturbo.com


I've a sample application based on MVC-model. A servlet that make a session an 
manager a database connection. I've developped with Jdeveloper, everything 
works fine. Now I've deployed to tomcat4.1.24, when i go to oher jsp page the 
session is null. Your help we'll be very useful
.
Rony Auguste
TurboSystem
Analyst-programmer.
---------------------------------------
here's the servlet source :
---------------------------------------
package pop;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.*;
import java.util.Properties;
import java.sql.*;

public class login extends HttpServlet implements java.io.Serializable
{

  private final String CONTENT_TYPE = "text/html; charset=windows-1252";
  public  Connection con;

  public void init(ServletConfig config) throws ServletException
  {
    super.init(config);

  }

public void doPost(HttpServletRequest request, HttpServletResponse response) 
throws ServletExce$
           {
            Properties conValues = Utilities.loadParams("/confile.properties" );
                String host   = (String)conValues.get( "HOST" );
                String sid    = (String)conValues.get( "SID" );
                String port   = (String)conValues.get( "PORT" );

               //set the database url
               String dburl = "jdbc:oracle:thin:@"+host+":"+port+":"+sid;
               String user   = request.getParameter("username") ;
              String pass   = request.getParameter("password") ;

              //declaration des variables de connection
              ResultSet rs   = null;
              Statement stmt =null;
               try
                    {
                       String driverName = "oracle.jdbc.driver.OracleDriver" ;
                       Class.forName(driverName);
                    }
             catch (ClassNotFoundException e)
                        {
                                System.out.println("Unable to load driver 
class : ");
                                 System.out.println(e.getMessage());
                     }
             // connecting to the database
             try {
                con = DriverManager.getConnection(dburl,user,pass);
 stmt= con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,   
ResultSet.CONCUR_REA$
                String querry="select a.AGENT_ID  from TRSF.AGENT a, 
TRSF.USER_AGENT u "+
                              "where a.AGENT_ID = u.AGENT_ID    and u.USER_ID  
= user";
                rs=stmt.executeQuery(querry) ;
              if (rs.next()) {
                  HttpSession session = request.getSession(true);
                   synchronized(session) {
                     session.setAttribute("uname",user);
                     session.setAttribute("agence",rs.getString(1));
                     session.setAttribute("con",con);
                    }
                 request.setAttribute("db",sid);

                 ServletContext context = getServletContext();
                 RequestDispatcher dispatcher=
                 context.getRequestDispatcher("/jsp/main.jsp");
                 dispatcher.forward(request,response);

              }
              } //end try connecting to the database

           catch(SQLException ex){
              response.setContentType(CONTENT_TYPE);
            PrintWriter out = response.getWriter();
            out.println("Message :"+ex.getMessage());
           out.println("Etat :"+ex.getSQLState());
          out.println("Code erreur:"+ex.getErrorCode()+"\n");
/*get catch

fin get catch*/
           }
        } //end  dopost

     }
} // end class

----------------------------------------
I could retrieve the session on the main.jsp forward by the servlet, but  for 
the other jsp nothing
---------------------------
ex:
<%@ page errorPage="error.jsp" %>
<%@ page session="true" %>
<%@ page import="java.sql.*" %>
<%@ page import = "java.io.*"  %>
<%
   HttpSession popsession = request.getSession(true);
   Connection con= null ;
   con = (Connection)popsession.getAttribute("con");
  if(con!=null){
      Statement stmt         = null;
      Statement stmt_date = null;
      ResultSet rset         = null;
      ResultSet rset_date = null;
      try {
             stmt = con.createStatement ();
             stmt_date = con.createStatement ();
             rset_date = stmt_date.executeQuery("select to_char
(sysdate,'dd/mm/rrrr') from dual")$
             rset =stmt.executeQuery("select ua.USER_ID||',',ua.NAME 
name,ua.AGENT_ID"+
            " from trsf.user_agent ua, trsf.agent ag where 
ua.agent_id=ag.agent_id and"+
            " ua.agent_id=trsf_agence.get_agence(user) order by 2");
            if (rset.next()) {
            rset_date.next() ;
   %>
.....
-----------
It returns null.

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message