Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using bean declared in JSP from Servlet

 
Dhaval Patel
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx Buzz, It worked out.

Dhaval Patel
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic