ajax动态时间显示jsp+ajax

jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>



  
    
    
    My JSP 'time2.jsp' starting page
    
	
	
	    
	
	
	

  
  	
  
    Time : 
    
    
  

 Servlet

package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TimeServlet extends HttpServlet {

	/* (non-Javadoc)
	 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		//super.doGet(req, resp);
		doPost(req, resp);
	}

	/* (non-Javadoc)
	 * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
//		super.doPost(req, resp);
		resp.setContentType("text/xml;charset=UTF-8");
		resp.setCharacterEncoding("UTF-8");

		PrintWriter out = resp.getWriter();
		DateFormat df = new SimpleDateFormat("北京时间:yyyy年mm月dd日 hh:mm:ss");
		out.print(df.format(new Date()));
	}

	
}

 web-xml



  
    index.jsp
  
  
  
  	ProvinceServlet
  	servlet.ProvinceServlet
  
  
  
  	ProvinceServlet
  	/ProvinceServlet
  
  
  
  
  	TimeServlet
  	servlet.TimeServlet
  
  
  
  	TimeServlet
  	/timeservlet
  

 

你可能感兴趣的:(jsp,ajax,ajax,jsp)