How can we call a java bean from a servlets in a MVC Design structure?
senthil sen
Ranch Hand
Joined: Oct 10, 2002
Posts: 182
posted
0
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
posted
0
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
posted
0
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!!!
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.