JAVA-WEB 笔记
Posted miao_a_miao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JAVA-WEB 笔记相关的知识,希望对你有一定的参考价值。
显示当前时间:
import java.io.IOException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet("/hello") public class HelloServlet extends HttpServlet{ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // TODO Auto-generated method stub DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String currentTime = dateFormat.format(new Date()); System.out.println(currentTime); req.setAttribute("currentTime", currentTime); req.getRequestDispatcher("/WEB-INF/jsp/hello.jsp").forward(req, resp); } } /* <%@ page pageEncoding="UTF-8" %> <html> <head> <title>Hello</title> </head> <body> <h1>Hello!</h1> <h2>Current time: ${currentTime}</h2> </body> </html> */
以上是关于JAVA-WEB 笔记的主要内容,如果未能解决你的问题,请参考以下文章