File>New>Web Project
填写项目名称Project Name,举例为andylife,这里利用的是默认存储路径,如需修正,把下面Use default location前面的勾去掉,并在Directory填写自己的地址
设置完成后点击Finish,新建完成
编写内容
打开WebRoot目录下的index.jsp,把编码改为utf-8
网页修正内容,显示日期韶光源码:
<%@ page language=34;java" import="java.util." pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<body>
<%
//设置刷新页面的韶光,每隔1秒钟刷新一次
response.setHeader("refresh", "10");
%>
当前的系统韶光是:
<%
//输出当前韶光
Calendar now = Calendar.getInstance();
out.print(now.get(Calendar.YEAR) + "年");
out.print(now.get(Calendar.MONTH) + 1 + "月");
out.print(now.get(Calendar.DATE) + "日");
out.print(now.get(Calendar.HOUR_OF_DAY) + "时");
out.print(now.get(Calendar.MINUTE) + "分");
out.print(now.get(Calendar.SECOND) + "秒 ");
out.print("星期");
switch (now.get(Calendar.DAY_OF_WEEK)) {
case 1:
out.print("日");
break;
case 2:
out.print("一");
break;
case 3:
out.print("二");
break;
case 4:
out.print("三");
break;
case 5:
out.print("四");
break;
case 6:
out.print("五");
break;
case 7:
out.print("六");
}
out.print(""+"<hr>");
out.print("ID Things need to be done IF DAILY "+"<br>");
%>
</body>
<body>
<%
out.print(""+"<hr>");
%>
</body>
</html>
运行
把页面支配到Tomcat上
点击ADD,然后选择我们的Tomcat做事器,点击Finish,然后点OK
点击阁下图标的小三角形,选择做事器,并运行
当我们在掌握台看到此信息时,做事器就开启成功了
前端浏览
在浏览器输入网址:http://localhost:8080/life/index.jsp
它表示的是,在本地8080端口下,life中的index.jsp