Wednesday, 19 February 2014

Java Bean Examples

Java Bean Class: Student.java
___________________________________________

package mydata;
public class Student {
 private int sid;
 private String sname;
 private double perct;

 public void setSid(int iid)
 {
   sid=iid;
 }
 public void setSname(String nm)
 {    sname=nm;  }

 public void setPerct(double pt)
 {     perct=pt;  }

 public int getSid() {   return sid; }
 public String getSname() { return sname; }
 public double getPerct() { return perct; }


}
_____________________________________________________________
 Bean Creation JSP Page Example 


Using JAVA BEAN :

<jsp:useBean id="s1" class="mydata.Student" />

<jsp:setProperty name="s1" property="sid" value='<%= Integer.parseInt(request.getParameter("sid"))%>' />
<jsp:setProperty name="s1" property="sname" value='<%= request.getParameter("sname")%>' />

<jsp:setProperty name="s1" property="perct" value='<%= Double.parseDouble(request.getParameter("perct"))%>' />


Using param attribute

<jsp:useBean id="s2" class="mydata.Student" scope="request" />

<jsp:setProperty name="s2" property="*"  />

<jsp:forward page="/WEB-INF/filedata/forwardbean.jsp" />

_______________________________________________________________________________
 Forwardbean.jsp example

Welcome to the ISTAR College

<h2> This is request forwarded page   </h2>

Here ..  Student information :

<jsp:useBean id="s2" class="mydata.Student"  scope="request" />


ID:<jsp:getProperty name="s2" property="sid" /><br>

Name: <jsp:getProperty name="s2" property="sname" /><br>

Percentage :<jsp:getProperty name="s2" property="perct" />

No comments:

Post a Comment