my dog learned polymorphism*
The moose likes JSP and the fly likes How to access Bean 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 "How to access Bean" Watch "How to access Bean" New topic
Author

How to access Bean

Arvind Mahendra
Ranch Hand

Joined: Jul 14, 2007
Posts: 1162
If I use a bean in my JSp like
<jsp:useBean id="userInfo" scope="request" class="com.beans.UserInfo" />

I tried accessing this in my servlet like:
UserInfo u1= (UserInfo)request.getAttribute(userInfo)

but it doesn't work. How can i have this bean be available in the servlet?


I want to be like marc
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Does UserInfo have a no args constructor?

Are you forwarding from your JSP to your servlet (if so, why?).
If not, request scope is probably not what you're looking for.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60804
    
  65

Originally posted by Arvind Birla:
but it doesn't work.

Does the keyboard burst into flames?

Seriously, "it doesn't work" doesn't tell us anything about your issue. What happened? What error did you get?
[ April 21, 2008: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Arvind Mahendra
Ranch Hand

Joined: Jul 14, 2007
Posts: 1162
UserInfo is a bean that is populated with data that the user fills out in the form. On this page I just use the line below to display what he entered.
<jsp:useBean id="userInfo" scope="request" class="com.beans.UserInfo" />

The line above is used to display the data to the user before entering in the dbase like below.

value="<cut value="${userInfo.emailAddr}" />">


I need the bean in a servlet I forward to when the user agrees to having this data put into a Dbase.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60804
    
  65

You are forwarding to a servlet from a JSP? Please be explicit on the chain of events.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to access Bean
 
Similar Threads
How to get data from bean to a string?
Keeping current logged user.
How can a bean to get a object in application scope
class property of a javabean
Using an Object property in my App