• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

redirect a bean?

 
Ramon Haayema
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You used the wrong bean scope.
 
Ramon Haayema
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please elaborate the following statement:
it all works under apache tomcat and eclipse.
 
Ramon Haayema
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apache tomcat 6.0 running with Eclipse.
thats where its running on.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, but where doesn't it work then?
 
Ramon Haayema
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the second ( MyshoppingCart ) the bean is empty
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic