package com.demo;

import java.io.*;
import java.util.*;
import java.text.SimpleDateFormat;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.WebServlet;

@WebServlet("/ShowTimeServlet")
public class ShowTimeServlet extends HttpServlet {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        response.setContentType("text/html;charset=gb2312");
        response.setCharacterEncoding("gb2312");

        PrintWriter out = response.getWriter();
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd a HH:mm:ss");
        String s = sdf.format(date);

        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<meta charset=\"gb2312\">");
        out.println("<meta http-equiv=\"refresh\" content=\"2\">");
        out.println("<title>显示时间</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h3 align=\"center\">每2秒钟刷新一次页面</h3><p>");
        out.println("<h3 align=\"center\">现在的时间是：" + s + "</h3><p>");
        out.println("</body>");
        out.println("</html>");
    }
}