aspose file tools*
The moose likes JSP and the fly likes redirect a bean? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "redirect a bean?" Watch "redirect a bean?" New topic
Author

redirect a bean?

Ramon Haayema
Greenhorn

Joined: May 17, 2008
Posts: 14
Hello,

Can please someone help me with the following problem.
after a login and data is taken out of the data base throu a sevlet the data is set into a bean and works fine in the first jsp file:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="nl.business.dbbean.*" %>
<%@ page session="true" %>
<jsp:useBean id="login" type="nl.business.dbbean.LoginBean" class="nl.business.dbbean.LoginBean" scope="session"></jsp:useBean>
<jsp:setProperty property="*" name="login" />

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Welcome customer : <jsp:getProperty name="login" property="customer" />
<p></p>

<a href="MyShoppingCart.jsp">Go to my shopping cart</a>
</body>
</html>
no problems so far.
but when i want to read the same bean in the myshoppingcart jsp the4 bean is empty

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="nl.business.dbbean.*" %>
<%@ page session="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="login" class="nl.business.dbbean.LoginBean" scope="application"></jsp:useBean>
<jsp:setProperty property="*" name="login" />

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>My current ShoppingCart</title>
</head>
<body>
<jsp:getProperty name="login" property="customer"/>

</body>
</html>

is there someting that i am missing?

it all works under apache tomcat and eclipse.

Thanks in advanced.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
You used the wrong bean scope.
Ramon Haayema
Greenhorn

Joined: May 17, 2008
Posts: 14
what scope do i need than.
becourse i tryed application also but the bean is still empty.
thanks for your help so far.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
In the 1st page you declared the bean in the session scope.
In the 2nd page you declared the bean in the application scope.

This way you're creating two different beans in different scopes. If you want to reuse the bean as created in the 1st page, you need to declare it with the same scope.
Ramon Haayema
Greenhorn

Joined: May 17, 2008
Posts: 14
have them both on session now.
problem still exsist....
even when both are on application.
got more ideas?
thanks so far
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Please elaborate the following statement:
it all works under apache tomcat and eclipse.
Ramon Haayema
Greenhorn

Joined: May 17, 2008
Posts: 14
Apache tomcat 6.0 running with Eclipse.
thats where its running on.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
OK, but where doesn't it work then?
Ramon Haayema
Greenhorn

Joined: May 17, 2008
Posts: 14
In the second ( MyshoppingCart ) the bean is empty
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Yes, I understood that. But you said that it works in Eclipse+Tomcat. Where doesn't it work then? In standalone Tomcat outside Eclipse or another appserver or so?
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Or did you rather mean that it runs on Eclipse+Tomcat?

In this case, nevermind.

I've never used jsp:useBean and jsp:setProperty intensively before, I just do it all the clean way using servlets and JSTL/EL. So I can be wrong, but isn't that jsp:setProperty in the 2nd page a bit superfluous? Isn't it overriding the bean's state with the current request parameters (which are obviously empty)?
Ramon Haayema
Greenhorn

Joined: May 17, 2008
Posts: 14
Well, the first jsp coms form a sevlet so there the bean is loaded with data but when i want to go to the second jsp the bean is empty (null).
i like to know how i can reuse the data in the bean in my total web pages.

thanks for the help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: redirect a bean?
 
Similar Threads
jsp:getProperty gives null
request time expression
include directive doesn't work
retrive serialize files data ERROR
calling jsp directl from HTML form