Java教程

java实现定时刷新

本文主要是介绍java实现定时刷新,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

servletdemo5.java代码:

package com.haidi8.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Random;

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

public class servletdemo5 extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setIntHeader("refresh", 1);
		Random r= new Random();
		response.getWriter().write(r.nextInt()+"");
		

		
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		
	}

}

web.xml代码:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <display-name></display-name>
  <servlet>
    <servlet-name>servletdemo5</servlet-name>
    <servlet-class>com.haidi8.servlet.servletdemo5</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>servletdemo5</servlet-name>
    <url-pattern>/servletdemo5</url-pattern>
  </servlet-mapping>	
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

运行效果:

 

这篇关于java实现定时刷新的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!