This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

How to get the bean object in servlet from jsp?  RSS feed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%@ page language="java" %>
<%@ page import="EmpBean" %>
<jsp:useBean id="user" class="EmpBean" scope="session">
<jsp:setProperty name="user" property="*"/>
</jsp:useBean>
<html>
<body>
<form method=post action=/abacus/servlet/SampleServlet>
<input type="text" name="empcode"><br>
<input type="text" name="empname"><br>
<input type="submit" value="submit">
</form>
</body>
</html>
I have the above jsp page which is submitted to the SampleServlet. How to pass the bean object "user" which is set in the Jsp to the servlet?
 
Ranch Hand
Posts: 235
Java Python Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see any reason why your servlet should'nt be able to access the said bean like any other regular class. Just use the beans instance to access the properties you had set using the JSP.
 
Ranch Hand
Posts: 687
Hibernate jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mukund,
u have defined the scope of the bean as session in the jsp hence in the servlet u can access it from the seeion object by using
EmpBean e = (EmpBean)session.getAttribute("user");
 
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem: you don't have the bean class in a package.

You will waste a lot of time chasingn weird errors if you don't put the bean class in a package. In addition to using the package name in the useBean tag:

you will have to import the package in both the JSP and the servlet.
Bill
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!