aspose file tools*
The moose likes Servlets and the fly likes How can we call a java bean from a servlets in a MVC Design structure? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How can we call a java bean from a servlets in a MVC Design structure?" Watch "How can we call a java bean from a servlets in a MVC Design structure?" New topic
Author

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

senthil sen
Ranch Hand

Joined: Oct 10, 2002
Posts: 184
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

Joined: Aug 28, 2002
Posts: 173
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

Joined: Jan 17, 2003
Posts: 1
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

Joined: Jun 25, 2001
Posts: 16305
    
  21

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 .


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can we call a java bean from a servlets in a MVC Design structure?