• Post Reply Bookmark Topic Watch Topic
  • New Topic

JavaBeans session lossing values  RSS feed

 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I'm trying to create a simple session bean that holds a users unique ID when they log in, this can then be retrieved by every page within the 'secure' section of my site.

The problem is the bean looses this value. The users ID value is parsed in OK but when you try to do a getUserID() nothing is returned.

I thought scope="session" meant that the bean would hold the value for as long as the session is open.

Below are some snipets of the code...

LoginServlet:
SessionBean sessionBean = new SessionBean();
sessionBean.setSessionID(iUserID);
request.setAttribute("sessionBean", sessionBean);

Bean:
package com.domain.beans;
import java.io.*;
public class SessionBean {
public SessionBean() {}
private int userID;

public void setSessionID(int userID) {
this.userID = userID;
}
public int getSessionID() {
return userID;
}
}

'secure' JSP pages:
<jsp:useBean id="sessionBean" class="uk.co.keatings.beans.SessionBean" scope="session" />
<%
int sessionID = sessionBean.getSessionID();
%>

Hope someone can help with this as it's starting to get on my nerves :-D

Cheers

Keith
 
Preetham Chandrasekhar
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you are using a bean,...the get and set methods must be the same as the property which in ur case wud be:

int userID;

public int getUserID() {
.......
}

public void setUserID(userID) {
}

change ur get and set methods to match your property name and that shud do it
 
Frederic Filiatrault
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Sorry but it`s not exactly this. The get/set properties have to match the properties used in the JSP file, not the instance variables of the class (It has nothing to do, you can name it as you want, it is internal).

I know it will sound stupid but can you check if your cookies are activated ? You described exactly what happen when the cookies on a navigator are blocked.
Also, as an advice, I would not use IExplorer for that, use Mozilla FireFox or Netscape. Why ? You can see the cookies, their values, their exp. date and can manually deleted them. IE is painful...



Hope this help !
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!