标签:coding generated bsp enc auto http img span response
显示当前时间:
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> */
标签:coding generated bsp enc auto http img span response
原文地址:http://www.cnblogs.com/cnblogs321114287/p/7898762.html