Use Object in entire app

If I use this line of code within a class which I call how can I use it in other parts of my web app? Like userInfo.firstName in a JSP.

UserInfo userInfo =new UserInfo(userfname);

My UserInfo class:

package com.ibm.drawinginquiry.rational;

publicclass UserInfo{

public String firstName;

public UserInfo(String fName){

firstName = fName;

}

}

[714 byte] By [SLDykea] at [2007-11-27 4:00:57]
# 1
Hi,Google on the singleton pattern.Kaj
kajbja at 2007-7-12 9:05:35 > top of Java-index,Java Essentials,New To Java...
# 2
Hy, I want to know about SRV Record configuration to work with Solaris 8, Iplanet 5.2 and MS Active Directory.Can anybody help me? Any suggestions? Thanks in advanceBy,chernandez@une.edu.ve
canrita at 2007-7-12 9:05:35 > top of Java-index,Java Essentials,New To Java...
# 3

I am not sure this is what I need. In the programming language I am used to I declare a variable to be public assign it a value and it is accessable throughout the entire session of the app.

So in my way of thinking.

I create a UserInfo class that accepts say one argument(fName) with a FirstName property. In a class that I call when a user logs on I create an object of the UserInfo class sending it the log on users firstname. Now I would expect to be able to get this property value at anytime and any where by using the userInfo.getFirstName() syntax.

This is not the case since I get cannot resolve userInfo everywhere except in the class where I created the userInfo object.

SLDykea at 2007-7-12 9:05:35 > top of Java-index,Java Essentials,New To Java...
# 4

> Hy,

>

> I want to know about SRV Record configuration to work

> with Solaris 8, Iplanet 5.2 and MS Active Directory.

>

> Can anybody help me? Any suggestions? Thanks in

> advance

>

>

> By,

>

> chernandez@une.edu.ve

Wrong thread, wrong forum, methinks.

DrLaszloJamfa at 2007-7-12 9:05:35 > top of Java-index,Java Essentials,New To Java...
# 5
> Can anybody help me? Any suggestions? Thanks in> advanceWhy did you post that question here?
kajbja at 2007-7-12 9:05:35 > top of Java-index,Java Essentials,New To Java...
# 6

> I am not sure this is what I need. In the programming

> language I am used to I declare a variable to be

> public assign it a value and it is accessable

> throughout the entire session of the app.

>

> So in my way of thinking.

>

> I create a UserInfo class that accepts say one

> argument(fName) with a FirstName property. In a class

> that I call when a user logs on I create an object of

> the UserInfo class sending it the log on users

> firstname. Now I would expect to be able to get this

> property value at anytime and any where by using the

> userInfo.getFirstName() syntax.

>

> This is not the case since I get cannot resolve

> userInfo everywhere except in the class where I

> created the userInfo object.

I understand what you want to do (at least I think so) and the singleton pattern is the answer to your question.

Kaj

kajbja at 2007-7-12 9:05:35 > top of Java-index,Java Essentials,New To Java...
# 7
> This is not the case since I get cannot resolve userInfo everywhere except in the class where I created the userInfo object.Since you mentioned JSP in passing, I assume this is a web app, not?What about adding it to the session scope?
DrLaszloJamfa at 2007-7-12 9:05:36 > top of Java-index,Java Essentials,New To Java...
# 8
How can I add it to the session scope?
SLDykea at 2007-7-12 9:05:36 > top of Java-index,Java Essentials,New To Java...
# 9

> Since you mentioned JSP in passing, I assume this is

> a web app, not?

Ah. I thought that he had a web app where he had done that, and now he wanted to do something similar in a java application. But it looks like you are correct, and that I didn't understand the question.

Kaj

kajbja at 2007-7-12 9:05:36 > top of Java-index,Java Essentials,New To Java...
# 10
HttpSession session = request.getSession();session.setAttribute("com.acme.your.key.here", object);If you are using a framework, it may have other ways to do this.For example, JSF lets you configure this in one of your XML config files.
DrLaszloJamfa at 2007-7-12 9:05:36 > top of Java-index,Java Essentials,New To Java...
# 11
Does each servlet/jsp have its own session. If so haow can I use the value of one property in all the servlets.
SLDykea at 2007-7-12 9:05:36 > top of Java-index,Java Essentials,New To Java...
# 12
> Does each servlet/jsp have its own session. If so> haow can I use the value of one property in all the> servlets.You don't understand the notion of a session. It's pretty basic. Do you have any books at all that discuss JSP/servlets?
DrLaszloJamfa at 2007-7-12 9:05:36 > top of Java-index,Java Essentials,New To Java...
# 13

First, a Java Server Page (JSP) is a Java servlet.

> Does each servlet/jsp have its own session. If so

> haow can I use the value of one property in all the

> servlets.

In the Web container of a Java web server, each invocation of a servlet creates a session (SessionContext).

If you want to share an object so that it is visible by all sessions, then you can store the object in the (ApplicationContext).

GhostRadioTwoa at 2007-7-12 9:05:36 > top of Java-index,Java Essentials,New To Java...
# 14

> each invocation of a servlet creates a session (SessionContext).

no

> f you want to share an object so that it is visible by all sessions, then you can store the object in the (ApplicationContext).

I think the OP wants to maintain user information, per user session, not globally.

DrLaszloJamfa at 2007-7-12 9:05:36 > top of Java-index,Java Essentials,New To Java...
# 15

I think that is correct. Please bare with me. I promise I wont stay ignorant forever. I need users to log on to the web app. Each user will fire a connection class that determines there authority to use various functions of the web app. I have classes, servlets, jsp's and what ever else I need to make this work.

The basics is an app used by an Engineering group to view, create and modify drawing data that resides on an AS400 database.

Say their authority is Guest. They need to only get and view data so my JSP would not show them modify or delete buttons.

The problem is the authority level was determined at log on and now they have moved through several servlets and JSP's.

Is this still one session? Or does each of the JSP's have its on session. If this is one session how do I get the session attributes from one JSP to another?

SLDykea at 2007-7-21 21:01:30 > top of Java-index,Java Essentials,New To Java...
# 16
The session, by definition, follows the user from page to page. It is associated with the user, not the page.
DrLaszloJamfa at 2007-7-21 21:01:30 > top of Java-index,Java Essentials,New To Java...