• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JavaBeans session lossing values

 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !
reply
    Bookmark Topic Watch Topic
  • New Topic