« يك مثال ساده JSP | صفحه اصلی | برقراري ارتباط بين JSP و Servlet »
نمايش ساعت با استفاده از jsp
July 3, 2007 02:51 PM
فايل CurrentTimeBean.java :
package javaborder;
import java.util.Date;
public class CurrentTimeBean {
public int hours;
public int minutes;
public CurrentTimeBean() {
Date now = new Date();
this.hours = now.getHours();
this.minutes = now.getMinutes();
}
public int hours;
public int minutes;
public CurrentTimeBean() {
Date now = new Date();
this.hours = now.getHours();
this.minutes = now.getMinutes();
}
public int getHours(){
return hours;
}
public void setHours(int Hours){
this.hours = Hours;
}
public int getMinutes(){
return minutes;
}
public void setMinutes(int Minutes){
this.minutes = Minutes;
}
}
return hours;
}
public void setHours(int Hours){
this.hours = Hours;
}
public int getMinutes(){
return minutes;
}
public void setMinutes(int Minutes){
this.minutes = Minutes;
}
}
فايل test.jsp :
<jsp:useBean id = "time" class= " javaborder.CurrentTimeBean"/>
<html>
<body>
Hour : <jsp:getProperty name = "time" property = "hours"/> <BR>
Minutes : <jsp:getProperty name = "time" property = "minutes"/> </body>
</html>
<html>
<body>
Hour : <jsp:getProperty name = "time" property = "hours"/> <BR>
Minutes : <jsp:getProperty name = "time" property = "minutes"/> </body>
</html>
دستور <jsp:useBean> براي استفاده از JavaBean ها در jsp استفاده مي شود. با اين دستور مي توان يك كلاس جاوا را مشخص نمود و نمونه اي از آن ايجاد كرد.
نظرخواهی