File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes simple use bean questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "simple use bean questions" Watch "simple use bean questions" New topic
Author

simple use bean questions

Manish Das
Greenhorn

Joined: Sep 03, 2003
Posts: 7
Q1. <CODE>
<P><jsp:useBean id="bUser" class="com.manish.testapplication.wssd.User" scope="session"/>
</CODE>
===========================
Above is my use bean code. I need to use the bUser and its property values to do some calculation/evaluation in a code which looks something like:
<CODE>
<%int count = bUser.messages.size() %>
</CODE>
where messages is a Vector but this preceding line of code is giving me null pointer exception.
However if I use the following code I can run it successfully:
================================================
<CODE>
<% com.manish.testapplication.wssd.User oUser = (com.manish.testapplication.wssd.User) request.getAttribute("bUser");
int count = oUser.messages.size(); %>
</CODE>
================================================
Is that a right thing to do?

Q2. What is the mechanism behind end of a session scope? What triggers the end? If I have a bean in a session scope in a JSP and I am passing the bean from JSP(1) => Servlet(1) => JSP(2). What happens if I hit the back button and come back to JSP(1) and repeat the action with a different instance of the bean.

Q3. How do I instantiate a session bean which has arguments in its contructor?
Sorry I am a bit confused.
[ October 17, 2003: Message edited by: Manish Das ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

1. Look at these two fragments from your code closely. What do you see wrong?

2. Your session is valid for all requests in the same session scope until either the session is invalidated by code, or it times out after a period of inactivity.
3. If it requires constructor args, it's not a bean.
Also, the UBB CODE tags use square brackets [] rather than angle brackets.
hth,
bear
[ October 17, 2003: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Manish Das
Greenhorn

Joined: Sep 03, 2003
Posts: 7
Thanks Bear,
that was an eye opener....
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: simple use bean questions
 
Similar Threads
STRUTS: client-side validation in jsp using DynaValidatorForm
Do I understand scope, redirects and JSPs correctly?
Newbie Q: ok to pass ResultSet from bean to JSP?
Some Brainbench JSP Q's.....Opinions required
Newbie - Declarations