<?XML version= "1.0" encoding= "UTF-8"?> <!--database Connection pool configuration file - <Context> <Resourcename= "Jdbc/connectionpool"Auth= "Application"type= "Javax.sql.DataSource"username= "root"Password= "root"Driverclassname= "Com.mysql.jdbc.Driver"URL= "jdbc:mysql://localhost:3306/pwapplication?relaxautocommit=true&zerodatetimebehavior= Converttonull "maxactive= "8"Maxidle= "4" /> </Context>
Then add code to the JSP page and get the time to format the time as you want.
<%@ page language= "Java"Import= "java.util.*" pageencoding= "UTF-8"%><%@ pageImport= "java.sql.*"%><%@ pageImport= "javax.naming.*"%><%@ pageImport= "Javax.sql.datasource,java.text.format,java.text.dateformat"%><%@ pageImport= "Java.text.SimpleDateFormat"%><%String Path=Request.getcontextpath (); String BasePath= Request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >Context Initctx=NewInitialContext (); Context CTX= (Context) initctx.lookup ("Java:comp/env")); //Get Connection Pool objectDataSource ds = (DataSource) ctx.lookup ("Jdbc/connectionpool"); //Create a connectionConnection conn =ds.getconnection (); System.out.println ("Conn=" +conn); Statement stmt=conn.createstatement (); String MySQL= "SELECT * FROM NOTIFICATION_TB"; ResultSet myrs=stmt.executequery (MySQL);//Execute Query%> <body>notification message list:<% while(Myrs.next ()) {%> <%String notiid=myrs.getstring ("Notiid"); String Notitheme=myrs.getstring ("Notitheme"); String noticontent=myrs.getstring ("Noticontent"); String notifier=myrs.getstring ("Notifier"); Timestamp Notitime=myrs.gettimestamp ("Notitime"); //set the time formatSimpleDateFormat SPF =NewSimpleDateFormat ("yyyy mm month dd Day hh mm min ss sec"); //format TimeString fmttime=Spf.format (notitime); %> <%System.out.println (Notitheme); System.out.println (noticontent); System.out.println (Notitime); System.out.println (Fmttime); %> <dt>>><a href= "notidetail?notiid=<%=notiid%>" ><%=notitheme%></a& gt;</dt> <dd> <div align= "right" > Publisher: <%= notifier%> </div> </dd> <% } %> </body>JSP uses the database connection pool method to obtain the database timestamp context.xml configuration, the JSP page formats the time into its own need format