Search This Blog

Sunday, 16 September 2012

Practical 27) You want to reduce the amount of Java coding in your JSP using a JavaBean component. (Hint: Use with the name of your bean).


Filename-inputdata.jsp
<html>
<form action="http://localhost:8090/wtad/def27/MyStudentBean.jsp">
Id
<input type="text" name="id" />
<br>
Name
<input type="text" name="name" />
<br>
Cellno
<input type="text" name="cellno" />
<br>
Local
<br>
true
<input type="radio" name="local" value="true"/>
<br>
false<input type="radio" name="local" value="false"/>
<br>
<input type="submit" />
</form>
</html>

Filename-Student.java

package def27;
public class Student
{
          private String id;
          private String name;
          private long cellno;
          private boolean local=false;

          public void setId(String idd)
          {
                   this.id=idd;
          }

          public void setName(String nm)
          {
                             this.name=nm;
          }

          public void setCellno(long mo)
          {
                   this.cellno=mo;
          }

          public void setLocal(boolean idd)
          {
                   this.local=idd;
          }

          public String getId()
          {
                   return id;
          }

          public String getName()
          {
                             return name;
          }

          public long getCellno()
          {
                             return cellno;
          }
          public boolean isLocal()
          {
                   return local;
          }
}

Filename-MyStudentBean.jsp

<html>
<body>
<jsp:useBean id="s1" class="def27.Student" />
<jsp:setProperty name="s1" property="id" />
<jsp:getProperty name="s1" property="id" />
<br>
<jsp:setProperty name="s1" property="name"  />
<jsp:getProperty name="s1" property="name" />
<br>
<jsp:setProperty name="s1" property="cellno"  />
<jsp:getProperty name="s1" property="cellno" />
<br>
<jsp:setProperty name="s1" property="local"  />
<jsp:getProperty name="s1" property="local" />

<jsp:include page="/def26/footer.jsp" />
</body>
</html>

Output

Id  
Name 
 
Cellno 
 
Local 
true 
 
false
 
1001 
ccd 
945678799 
true

No comments:

Post a Comment