码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA-WEB 笔记

时间:2017-11-26 14:04:50      阅读:182      评论:0      收藏:0      [点我收藏+]

标签: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>


*/
View Code

 

JAVA-WEB 笔记

标签:coding   generated   bsp   enc   auto   http   img   span   response   

原文地址:http://www.cnblogs.com/cnblogs321114287/p/7898762.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!