I solved my problem.

Tomcat Session do not seem to quite work across JSP and Servlets.

When I start with "<WEBAPP>/servlet/LocationServlet" and it works
because if the session is new then it is created as usual
because the model Java bean is add to session.

When I start the app with "/locationview.jsp".
it does n't work even when I put "<%@page session="true">.
even when add model Javabean to the session even tho
you strictly shouldn't.

Weird.

In a real application, I guess, you'd have a login screen
and attach all the Worker Java Beans the session when the user authenticates
so you 'd never go straight to be view JSP.

--
Peter Pilgrim
G.O.A.T
                    "The Greatest of All Time"



---------------------------------------- Message History 
----------------------------------------


From: [EMAIL PROTECTED] on 17/11/2000 12:48

Please respond to [EMAIL PROTECTED]

To:   [EMAIL PROTECTED]
cc:
Subject:  Developing with Tomcat 3.2beta



I am trying to write a mini test MVC with JSP as a test with Tomcat 3.2B
I wrote two classes :

     <WEBAPP>/ROOT/WEB-INF/classes/LocationModel
     <WEBAPP>/ROOT/WEB-INF/classes/LocationController

I am creating a session object in both the JSP and the Servlet with

public class LocationController extends HttpServlet
{
    public void doGet( HttpServletRequest req, HttpServletResponse res )
        throws ServletException, IOException
    {
        // Get the current session object, create one if necessary
        HttpSession session = req.getSession(true);

        String action = req.getParameter("action");
        LocationModel model = (LocationModel)
            session.getAttribute("location_model");       /*  at 
LocationController.doGet(LocationController.java:62) */
        if ( model == null ) {
            // If the session does not have a model then create
            // a new one and add it to the session
            model = new LocationModel();
            session.setAttribute("location_model", model );
        }

     // ....

        RequestDispatcher rd = 
getServletContext().getRequestDispatcher("locationview.jsp");
        rd.forward( req, res );
    }


I have also put the model in the session inside the JSP (locationview.jsp) and
add a form with action that calls "/servlet/LocationController"

<%
        LocationModel model = (LocationModel)
            session.getAttribute("location_model");
        if ( model == null ) {
            model = new LocationModel();
            session.setAttribute("location_model", model );
        }
%.

Why do I get a class cast exception?
Is tomcat telling me it cant find the class?
Is the session the same across the JSP and controller servlet?
How does Tomcat find the Java object classes it uses?

Any help appreciated

Error: 500

Location: /servlet/LocationController

Internal Servlet Error:

java.lang.ClassCastException: LocationModel
        at LocationController.doGet(LocationController.java:62)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:503)
        at org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:597)
        at org.apache.tomcat.servlets.InvokerServlet.service(InvokerServlet.java:257)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:503)
        at org.apache.tomcat.core.ContextManager.service(ContextManager.java:559)
        at 
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:160)
        at 
org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoint.java:338)
        at java.lang.Thread.run(Thread.java:484)

--
Peter Pilgrim
G.O.A.T
                    "The Greatest of All Time"



--

This e-mail may contain confidential and/or privileged information. If you are not the 
intended recipient (or have received this e-mail in error) please notify the sender 
immediately and destroy this e-mail. Any unauthorised copying, disclosure or 
distribution of the material in this e-mail is strictly forbidden.

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to