> OK, now what failure symptoms are you seeing?
The JSP is presented to the user, the user fills in the detail and it gets
send to the servlet (the controller), the servlet gets the request object
and grabs the session instance. When it trys to grab the session instance it
is always null.
If I replace the servlet with a JSP as the contoller, this works fine. This
suggests seems to suggest that there isn't a continuation of a persistant
session between JSPs and Servlets in Tomcat, but I could be wrong. Looking
through the newsgroup it seems that quite a lot of people have had this
problem.
However, I have been researching several other servlet runners and they also
seem to be fine, although not all of them support JSP 1.1
-----Original Message-----
From: Craig R. McClanahan [mailto:[EMAIL PROTECTED]]
Sent: 10 April 2000 17:59
To: Rajesh Shah
Cc: [EMAIL PROTECTED]
Subject: Re: Session using Tomcat
Rajesh Shah wrote:
> I could only find examples with Tomcat for servlet sessions. The
> JSP->Servlet->JSP demo does not use sessions.
>
> Here are sample code snippets as requested -->
>
> -----------------------------------
> Here is the Servlet code that I am using:
>
> HttpSession session = request.getSession(false);
> if(session == null) {
> System.err.println("Session is null redirecting back to the
> registration jsp");
> response.sendRedirect(Links.REGISTER_JSP);
> }
This is similar to code in my "Model 2" controller servlet, when I want it
to
enforce the existence of a session. The only difference is that I use
RequestDispatcher.forward() instead, because it's faster.
>
> -----------------------------------
> Here is the JSP code:
>
> <%@ page import="com.evolution.examples.RegistrationFormConstants,
> com.evolution.examples.RegistrationFormBean,
> com.evolution.examples.Links" %>
> <%@ page errorPage="../error/error.html" %>
Because you are not setting the "session" attribute, the default value
(true)
should say that this page participates in sessions.
>
> <%--
> * Basic registration example. Is used for entry of a name and email
> address.
> --%>
> <jsp:useBean id="registrationFormBean" scope="session"
> class="com.evolution.examples.RegistrationFormBean" />
> <jsp:setProperty name="registrationFormBean" property="*" />
This should work. I've often seen this syntax as well:
<jsp:useBean id="registrationFormBean" scope="session"
class="com.evolution.examples.RegistrationFormBean">
<jsp:setProperty name="registrationFormBean" property="*"/>
</jsp:useBean>
as described in Section 2.13.1 of the JSP 1.1 spec. It is used in the case
where you want the properties set only if the bean is created by this call.
>
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
> "http://www.w3.org/TR/html4/loose.dtd">
> <HTML>
> <HEAD>
> <TITLE>Web Applications - Login</TITLE>
> <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
> <META HTTP-EQUIV="Cache-Control" CONTENT="no-store">
> <LINK REL="STYLESHEET" HREF="<%= Links.STYLE_SHEET %>"
> TYPE="text/css"></LINK>
> </HEAD>
> <BODY>
> <H2>Web Applications Standards Template - Example</H2>
> <FORM ACTION="<%= Links.REGISTER_SERVLET %>" METHOD="POST">
>
> <TABLE>
> <TR>
> <TD ALIGN="RIGHT">* First Name</TD>
> <TD><INPUT TYPE="text" SIZE="20" NAME="<%=
> RegistrationFormConstants.FIRST_NAME %>" VALUE="<jsp:getProperty
> name="registrationFormBean" property="firstName" />"></TD>
> <TD CLASS="error"><%=
> registrationFormBean.getErrorMsg(RegistrationFormConstants.FIRST_NAME)
> %></TD>
> </TR>
> etc.... etc.... etc....
> </TABLE>
> <P>
> <INPUT TYPE="SUBMIT"></INPUT>
> </P>
> </FORM>
> </BODY>
> <HTML>
> -----------------------------------
>
> Any help would be appreciated.
>
> Many Thanks... Raj.
OK, now what failure symptoms are you seeing?
Craig
===========================================================================
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