source file name: timeform.html
<html>
<head>
<title>JSP Time Bean</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
</head>
<body>
<form action="http://localhost:8080/JspWebApplication/timejsp.jsp" method="post" >
Enter Hours : <input type="number" name="t1" />
<br >
Enter Minutes : <input type="number" name="t2" />
<br>
Enter Seconds : <input type="number" name="t3" />
<br>
<input type="submit" value="Submit" />
</form>
</body>
</html>
<%! int h,m,s; %>
<%
h=Integer.parseInt(request.getParameter("t1"));
m=Integer.parseInt(request.getParameter("t2"));
s=Integer.parseInt(request.getParameter("t3"));
out.println("<h2>given Hours : "+h+" Miuntes: "+m+" Seconds: "+s);
%>
<jsp:useBean id="mybean" class="mybeans.timebean" />
<br> <h1> Time from Bean </h1>
<br>
<h2>
Hours are:
<jsp:setProperty name="mybean" property="hrs" value="<%=h %>" />
<jsp:getProperty name="mybean" property="hrs" />
<br> Minutes are:
<jsp:setProperty name="mybean" property="min" value="<%=m %>" />
<jsp:getProperty name="mybean" property="min" />
<br> Seconds are:
<jsp:setProperty name="mybean" property="sec" value="<%=s %>" />
<jsp:getProperty name="mybean" property="sec" />
</h2>
output:
Time Bean class
package mybeans;
public class timebean {
int hrs,min,sec;
public timebean()
{ }
public void sethrs(int a)
{
hrs=a;
}
public int gethrs()
{
return hrs;
}
public void setmin(int b)
{
min=b;
}
public int getmin()
{
return min;
}
public void setsec(int c)
{
sec=c;
}
public int getsec()
{
return sec;
}
}
0 Comments
Post a Comment