1.认识 Ajax

普通:

package com.java1234.web;

import java.io.IOException;

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

public class GetNameServlet extends HttpServlet{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest request,HttpServletResponse response)
			throws servletexception,IOException {
		this.doPost(request,response);
	}

	@Override
	protected void doPost(HttpServletRequest request,IOException {
		request.setAttribute("name","波多野结衣");
		request.getRequestdispatcher("common.jsp").forward(request,response);
	}
	
	

}
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<Meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
  <%
  Object obj = application.getAttribute("count");
     if(obj==null){
   Integer count = 1;
   application.setAttribute("count",count);
   
   }else{
   Integer count = (Integer)obj;
   count++;
   application.setAttribute("count",count);
   }
   %>
</head>
<link href="css/slide.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.SuperSlide.2.1.1.js"></script>
<script type="text/javascript">
	$(function(){
			$("#focus").hover(function(){$("#focus-prev,#focus-next").show();},function(){$("#focus-prev,#focus-next").hide();});
			$("#focus").slide({ 
				mainCell:"#focus-bar-Box ul",targetCell:"#focus-title a",titCell:"#focus-num a",prevCell:"#focus-prev",nextCell:"#focus-next",effect:"left",easing:"easeInOutCirc",autoplay:true,delayTime:200
			})
		})
</script>
<body>
<div style="text-align: center;">
	<div style="padding: 10px;"><input type="button" style="border: 1px solid red;" value="获取姓名" onclick="javascript:window.location='getName'"/>&nbsp;&nbsp;<input type="text" name="name" value="${name }" style="border-bottom: 1px solid red"/>&nbsp;&nbsp;页面刷新次数:<font color="red">${count }</font></div>
</div>
<div id="focus">
<div class="hd">
<div class="focus-title" id="focus-title">
    <a href="http://www.java1234.com"><span class="title">《王的女人》</span>于正版霸王别姬 陈乔恩变腹黑大战情敌袁姗姗</a>
    <a href="http://www.java1234.com"><span class="title">《盲探》</span>刘德华、郑秀文、杜琪峰香港电影铁三角十年归来</a>
    <a href="http://www.java1234.com"><span class="title">《爸爸去哪儿》</span>众星爸厨艺比拼犯难(2013-10-18期)</a>
    <a href="http://www.java1234.com"><span class="title">《到爱的距离》</span>李晨张馨予谱写爱之终曲</a>
    <a href="http://www.java1234.com"><span class="title">《天台》</span>周杰伦自导自演  传递超屌正能量</a>
</div>
    <a class="hdicon" href="http://www.java1234.com"></a>
    </div>
    <div class="focus-bar-Box" id="focus-bar-Box">
      <ul class="focus-bar">
        <li><a href="http://www.java1234.com"><img src="images/01.jpg"></a></li>
        <li><a href="http://www.java1234.com"><img src="images/02.jpg"></a></li>
        <li><a href="http://www.java1234.com"><img src="images/03.jpg"></a></li>
        <li><a href="http://www.java1234.com"><img src="images/04.jpg"></a></li>
        <li><a href="http://www.java1234.com"><img src="images/05.jpg"></a></li>
      </ul>
    </div>
    <a href="http://www.java1234.com" class="btn-prev" onclick="return false;" hidefocus="" id="focus-prev"></a>
    <a href="http://www.java1234.com" class="btn-next" onclick="return false;" hidefocus="" id="focus-next"></a>
  <div class="ft">
    <div class="ftbg"></div>
    <div id="focus-num" class="change">
        <a class=""></a>
        <a class=""></a>
        <a class=""></a>
        <a class=""></a>
        <a class=""></a>
    </div>
  </div>
</div>
</body>
</html>

AJAX:

package com.java1234.web;

import java.io.IOException;
import java.io.PrintWriter;

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

public class GetAjaxNameServlet extends HttpServlet{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest request,IOException {
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out=response.getWriter();
		out.println("波多野结衣");
		out.flush();
		out.close();
	}
	
	

}
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<Meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
  <%
  Object obj = application.getAttribute("count2");
     if(obj==null){
   Integer count = 1;
   application.setAttribute("count2",count);
   
   }else{
   Integer count = (Integer)obj;
   count++;
   application.setAttribute("count2",delayTime:200
			})
		})
		
	function loadName(){
		var xmlHttp;
		if(window.XMLHttpRequest){
			xmlHttp=new XMLHttpRequest();
		}else{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlHttp.onreadystatechange=function(){
			if(xmlHttp.readyState==4 && xmlHttp.status==200){
				document.getElementById("name").value=xmlHttp.responseText;
			}
		};
		xmlHttp.open("get","getAjaxName",true);
		xmlHttp.send();
	}
</script>
<body>
<div style="text-align: center;">
	<div style="padding: 10px;"><input type="button" style="border: 1px solid red;" value="获取姓名" onclick="loadName()"/>&nbsp;&nbsp;<input type="text" id="name" name="name" value="${name }" style="border-bottom: 1px solid red"/>&nbsp;&nbsp;页面刷新次数:<font color="red">${count2 }</font></div>
</div>
<div id="focus">
<div class="hd">
<div class="focus-title" id="focus-title">
    <a href="http://www.java1234.com"><span class="title">《王的女人》</span>于正版霸王别姬 陈乔恩变腹黑大战情敌袁姗姗</a>
    <a href="http://www.java1234.com"><span class="title">《盲探》</span>刘德华、郑秀文、杜琪峰香港电影铁三角十年归来</a>
    <a href="http://www.java1234.com"><span class="title">《爸爸去哪儿》</span>众星爸厨艺比拼犯难(2013-10-18期)</a>
    <a href="http://www.java1234.com"><span class="title">《到爱的距离》</span>李晨张馨予谱写爱之终曲</a>
    <a href="http://www.java1234.com"><span class="title">《天台》</span>周杰伦自导自演  传递超屌正能量</a>
</div>
    <a class="hdicon" href="http://www.java1234.com"></a>
    </div>
    <div class="focus-bar-Box" id="focus-bar-Box">
      <ul class="focus-bar">
        <li><a href="http://www.java1234.com"><img src="images/01.jpg"></a></li>
        <li><a href="http://www.java1234.com"><img src="images/02.jpg"></a></li>
        <li><a href="http://www.java1234.com"><img src="images/03.jpg"></a></li>
        <li><a href="http://www.java1234.com"><img src="images/04.jpg"></a></li>
        <li><a href="http://www.java1234.com"><img src="images/05.jpg"></a></li>
      </ul>
    </div>
    <a href="http://www.java1234.com" class="btn-prev" onclick="return false;" hidefocus="" id="focus-prev"></a>
    <a href="http://www.java1234.com" class="btn-next" onclick="return false;" hidefocus="" id="focus-next"></a>
  <div class="ft">
    <div class="ftbg"></div>
    <div id="focus-num" class="change">
        <a class=""></a>
        <a class=""></a>
        <a class=""></a>
        <a class=""></a>
        <a class=""></a>
    </div>
  </div>
</div>
</body>
</html>

相关文章

IE6是一个非常老旧的网页浏览器,虽然现在很少人再使用它,但...
PHP中的count()函数是用来计算数组或容器中元素的个数。这个...
使用 AJAX(Asynchronous JavaScript and XML)技术可以在不...
Ajax(Asynchronous JavaScript and XML)是一种用于改进网页...
本文将介绍如何通过AJAX下载Excel文件流。通过AJAX,我们可以...
Ajax是一种用于客户端和服务器之间的异步通信技术。通过Ajax...