dear all,
so far i have covered Database ,
EJB access in servelet.in this
thread i am going to give you example for JavaBean used in
jsp page running under weblogic server.
------------------------------------------------------------------------------------------------------------- JavaBean Class code(jspBeanTest.java) package example;
import java.io.Serializable;
public class jspBeanTest
implements Serializable{
private
String size = "Medium";
public void setSize(String size){
this.size = size;
}//end setSize()
public String getSize(){
return size;
}//end getSize()
public String exposedMethod(){
return "The size is " + size;
}//end exposedMethod()
}//end class jspBeanTest
----------------------------------------------------------------------------------------------------- JSP page code(size.jsp) <html>
<body>
<P>Examplep<BR><BR>
<P> Create or locate an instance of the<BR>
bean named:<BR><BR>
example.jspBeanTest.
<jsp:useBean
id="theBean"
scope="page"
class="example.jspBeanTest" />
<P>Display default size property of the <BR>
bean using the getter mehod.<BR><BR>
<%= theBean.getSize() %>
<P>Set the size property of the bean to<BR>
Large using the setter method.<BR><BR>
<% theBean.setSize("Large"); %>
<P>Get and display the size property<BR>
again using the getter method.<BR><BR>
<%= theBean.getSize() %>
<P>Invoke an exposed method on the bean.
<BR><BR>
<%= theBean.exposedMethod() %>
<P>Have a good day.
</body>
</html>
---------------------------------------------------------------------------------- deployment 1. create Directory structure like this :
App root -
-\WEB-INF
-\classes
-\example
2.put your compile class file of JavaBean in example directory.
3.put your jsp file in root directory.as jsp does not required entry in deployment desc. your work is over.
--------------------------------------------------------------------------------- run the server and type in address bar :
http://hostname:7001/size.jsp bye
bharat
SCJP2