aspose file tools*
The moose likes Servlets and the fly likes Using bean declared in JSP from Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Using bean declared in JSP from Servlet" Watch "Using bean declared in JSP from Servlet" New topic
Author

Using bean declared in JSP from Servlet

Dhaval Patel
Greenhorn

Joined: Jan 02, 2001
Posts: 7
Hi All,
In a jsp file i use
<jsp:useBean id="mybean" scope="request" class="MyBeanClass"/>
<jsp:setProperty name="mybean" property="*"/>
<jsp:forward page="/servlet/myServlet" />
In my servlet file myServlet I want to use the bean..
I don't know how to use the mybean in servlet to get the value set in the jspfile..
Any hints would be a gr8 help..
thanx
Dhaval Patel.
SCJP2
Buzz Andersen
Ranch Hand

Joined: Aug 28, 2001
Posts: 54
Since you are forwarding to the servlet, and your bean is in request scope, you can simply get the bean off the request. Like this:
// Get the bean off the request.
MyBeanClass theBean = (MyBeanClass) request.getAttribute("mybean");
Then you can simply deal with the bean as you would normally (i.e. theBean.getX(), theBean.getY()).
Originally posted by Dhaval Patel:
Hi All,
In a jsp file i use
<jsp:useBean id="mybean" scope="request" class="MyBeanClass"/>
<jsp:setProperty name="mybean" property="*"/>
<jsp:forward page="/servlet/myServlet" />
In my servlet file myServlet I want to use the bean..

Dhaval Patel
Greenhorn

Joined: Jan 02, 2001
Posts: 7
Thanx Buzz, It worked out.

Dhaval Patel
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Using bean declared in JSP from Servlet