*
The moose likes Servlets and the fly likes Accessing JSP beans from a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Accessing JSP beans from a servlet" Watch "Accessing JSP beans from a servlet" New topic
Author

Accessing JSP beans from a servlet

Bill Clar
Ranch Hand

Joined: Sep 21, 2006
Posts: 150

Am I correct in assuming that any bean defined and set in a JSP cannot be accessed in a servlet?

My form entry JSP...



In MinutesServlet...



...indexBean is null.

I just want to verify that my assumption is correct so that I can go about finding another way to extract the HTML form data.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

You've put the cart before the horse, collecting form info in the JSP before the form is even presented to the user.

You're also making it too complicated. Simply submit the form to the servlet and collect the data using the getParameter() family of methods on the request.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bill Clar
Ranch Hand

Joined: Sep 21, 2006
Posts: 150

I answered my own question on my lunch break.

indexBean is null because my JSP's form action is the servlet. Any HTML submission will take the request directly to the servlet, bypassing the Javabean initialization and setProperty steps.

In order to access indexBean from the servlet I would need to make the form action the JSP page. In the JSP I would need to forward the request to the servlet. This requires the use of scriptlets which I wish
to avoid.
Bill Clar
Ranch Hand

Joined: Sep 21, 2006
Posts: 150

Thanks Bear.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing JSP beans from a servlet
 
Similar Threads
Bean standard action doubt
JavaBeans and Servlets
How to store bean data into a JSP variable?
I have this strange display problem
Question in getProperty