Returning object created 'in' bean onto a page

A

Amit

Hello everybody:

I am trying to use a session level object created (and filled) in a
java bean. The problem is to verify user id and pwd provided, and if
they are valid, create and return a user object. This user object is
intended to have a session scope. The exact setup is as follows;

1. The user id and pwd are passed to the jsp page from login.html
page.

2.The jsp page contains a reference to the object theUser, that i want
to use with session scope
<jsp:useBean id='theUser' scope='session' class='User'>

3. There is another bean on the page, log, an object of login class.
This bean contains a method to check the database, and if user exists,
it returns a User object.

uid=request.getParameter("userid");
pwd=request.getParameter("passwd");
..
..
..
theUser = log.checkLogin(uid,pwd);
if (theUser==null)
{
%>
<h3> Login Failed </h3>
<a href="login.html"> Please Try Again </a>
<%
}

The code in Login.checkLogin is as follows. Presently i have hardcoded
the values,instead of accessing the database.

public User checkLogin(String userid,String passwd)
{
User user = null;
if(userid.equals("user") && passwd.equals("123"))
{
user = new User("rishi", "yadav", "Mr.", "","M") ;
}
return user;
}

4. Now comes the actual problem. theUser is able to access the
values stored in returned object, and i am able to display them. But
as soon as i go to some other page ( using forward ), the theUser
object exists alright, but it doesnt contain the values. My guess is
that since i am setting the values in checkLogin() and passing only a
reference, the reference has only page scope. So what should I do to
be able to use a object created in a bean and returned to a page?

Any, really any comments and suggestions shall be more than welcome

Thanks for your time

Amit
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top