首页>代码>java servlet实现根据时间提醒用户休息>/servletGT/src/com/hbjd/servlet/Day.java
package com.hbjd.servlet;

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Day extends HttpServlet {
	public void init(ServletConfig config) throws ServletException {
		super.init(config);

	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=GBK");// 设定中文
		PrintWriter out = response.getWriter(); // 使用输出流,输出信息
		out.println("<HTML>");
		out.println("<BODY>");
		Calendar calendar = Calendar.getInstance(); // 创建一个日历对象。
		calendar.setTime(new Date());// 用当前时间初始化日历时间。
		int hour = calendar.get(Calendar.HOUR_OF_DAY), minute = calendar
				.get(Calendar.MINUTE), second = calendar.get(Calendar.SECOND);
		if (hour >= 22) {
			response.sendRedirect("Night"); // 重定向。
		} else {
			out.print("现在北京时间是:");
			out.print(hour + ":" + minute + ":" + second);
		}
		out.println("</BODY>");
		out.println("</HTML>");
	}

}
最近下载更多
liu222  LV7 2021年5月6日
biqugedalao  LV1 2020年10月12日
苏屿999  LV9 2019年6月7日
807051023  LV1 2019年4月7日
清平乐  LV1 2019年3月20日
aolafu  LV2 2019年1月10日
x1501879136  LV1 2018年12月25日
1375948  LV1 2018年11月14日
ershan  LV1 2018年10月13日
CLATZJ  LV19 2018年7月25日
最近浏览更多
asddwh  LV12 2023年12月29日
西瓜哥哥  LV4 2023年12月17日
溪若白  LV1 2023年7月13日
hhj2002  LV2 2023年6月9日
alonely23  LV1 2022年10月20日
1635162218  LV9 2022年5月31日
FreddieLee  LV3 2022年4月29日
15137309085 2022年3月15日
暂无贡献等级
gaohd123456789  LV8 2022年1月21日
wanglinddad  LV54 2021年12月22日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友