Calendarclass.java
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Calendar;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet calendarclass</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet calendarclass at " + request.getContextPath() + "</h1>");
out.println("</body>");
out.println("</html>");
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
Calendar rightNow = Calendar.getInstance();
int hour = rightNow.get(Calendar.HOUR_OF_DAY);
out.println("Current hour is "+hour);
out.println("<br><br><br>");
if((hour >6)&&(hour <12)){
out.println("<b>GOOD MORNING</b>");
}
if((hour >=12) && (hour<=15)){
out.println("GOOD AFTER NOON");
}
if ((hour > 15) && (hour <=21)){
out.println("<b><center>GOOD EVENING</center></b>");
}
if ((hour >21) && (hour <=24)){
out.println("GOOD NIGHT");
}
}
}
OUTPUT
No comments:
Post a Comment