File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can we call a java bean from a servlets in a MVC Design structure?

 
senthil sen
Ranch Hand
Posts: 184
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to call a java bean in a servlet and use the properties of the java bean in a servlets.?
In jsp we can use <usebean> tag but in servlets??
 
boyet silverio
Ranch Hand
Posts: 173
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in page, e.g.
<jsp:useBean id="bic" class="BallPen" scope="request"/>
in servlet.e.g.
BallPen bp = (BallPen)request.getAttribute("bic");
hope this helps.
[ January 17, 2003: Message edited by: boyet silverio ]
 
SunMS Bridge
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can directly create an instance of the bean and start using the methods in the bean. Make sure you import the package before you access the methods.
import xxx.beans.color;
...
...
Color myColor = new Color();
// to set the bean values
myColor.setRed("23");myColor.setBlue("55");
myColor.setGreen("66");
// to get the bean values
String red = myColor.getRed("23");
String blue= myColor.setBlue("55");
String green = myColor.setGreen("66");
That should work!!!
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17627
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, you can be "MVS-like", but as I've been occasionally known to explain, TRUE MVC isn't possible under the restrictions of HTTP.
Actually, the bean property tags in JSPs do little more than resolve to the same set/get methods you invoke in servlets.
And after all, that's the defining characteristic of a JavaBean - a component object whose properties are accessed with get/set methods.
You can also do MVC-like (Model 2, to be precise) using the Jakarta Struts framework. See http://jakarta.apache.org/struts .
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic