Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP, Beans and Session  RSS feed

 
Raghav Sam
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem I am facing is that Beans does not get(retrieve) the properties in a new JSP page (not the one in which the properties were originally set.). I am using the Model 2 architecture (MVC pattern). JSP is for View and Beans is the Model, Servlets control.
I have a form which uses a bean to set all the properties. I want to display these proerties in another JSP page. The problem is when I use <jsp:getProperty...>, it does not retrieve the property; it returns 'null'. what could be the problem?
For eg:-
Let,
Bean Name: CustomerBean
JSP Page 1: GetInfo
JSP Page 2: PrintInfo
JSP Page 1: GetInfo:
<%@ page language="java" session="true" %>
<jsp:useBean id="customer" scope="session" class="CustomerBean" />
<jsp:setProperty name="customer" property="*" />
.
.
//some code

JSP Page 2: PrintInfo:
<%@ page language="java" session="true" %>
.
.
Customer Name: <jsp:getProperty name="customer" property="customerName" /> //(returns 'null')
.
.
//some code
I have checked the classpath, session configuration in Tomcat(session timeout basically).....nothing helps.
Any idea?


------------------
-------
Raghav.
 
Anil Vupputuri
Ranch Hand
Posts: 527
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the server version whether it is Jsp 1.1 compliant or not. And check out in ur bean and give some testing statements in getters/setters to check whether being called or not.
 
Raghav Sam
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anil,
Yes, Tomcat 3.2.1 is compliant with JSP 1.1.
The bean has been thoroughly tested. All the methods work ! The problem as I said is only with the next page. If I use <jsp:getProperty...> and print the properties in the same page(JSP Page 1) itself, it works perfect. Thats why I have a doubt with the session or Tomcat config.
Does Tomcat 3.2.1 have a known bug/problem while handling JSP, Beans and Session?
I actually tried a roundabout method using servlets (without using Bean), i.e., using request.getParameter()...and directly manipulating the properties. It works !

------------------
-------
Raghav.
[This message has been edited by Raghav Sam (edited April 24, 2001).]
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your second page, did you remember to specify the correct scope for the customer bean? Remember, the default is page scope.
- Peter
 
Dustin Marx
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ran into this once when moving Java code out of previously-written (by someone else) JSPs and into JavaBeans and custom tag Java handler classes. It was happening in my case because the developer who had written the JSP had embedded a session.invalidate() call way down in the page inside some other Java code. So, even though the bean property was set on that page, the entire session (including that "session" scope property) was invalidated before the page transferred control to the second page that needed the property.
Short version: Look for a session.invalidate() call in your JSPs.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!