jquery 实现Ajax

客户端jsp

<wbr></wbr>

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<wbr>&lt;head&gt;<br><wbr><wbr><wbr>&lt;base href="&lt;%=basePath%&gt;"&gt;<br><wbr><wbr><wbr>&lt;title&gt;My JSP 'index.jsp' starting page&lt;/title&gt;<br><wbr><wbr><wbr>&lt;meta http-equiv="pragma" content="no-cache"&gt;<br><wbr><wbr><wbr>&lt;meta http-equiv="cache-control" content="no-cache"&gt;<br><wbr><wbr><wbr>&lt;meta http-equiv="expires" content="0"&gt;<wbr><wbr><wbr><br><wbr><wbr><wbr>&lt;meta http-equiv="keywords" content="keyword1,keyword2,keyword3"&gt;<br><wbr><wbr><wbr>&lt;meta http-equiv="description" content="This is my page"&gt;<br><wbr><wbr><wbr>&lt;!--<br><wbr><wbr><wbr>&lt;link rel="stylesheet" type="text/css" href="styles.css"&gt;<br><wbr><wbr><wbr>--&gt;<br><span style="color:#FF0000; word-wrap:normal; word-break:normal"><wbr>&lt;script type="text/javascript" src="jquery-1.6.2.js"&gt;&lt;/script&gt;<br><wbr>&lt;script type="text/javascript"&gt;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>$(function(){<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>$("#buid").click(function(){<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>$.ajax({<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>type:"POST",<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>url:"Ser",<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>dateType:"html",<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>data:{'n1':'n1val','n2':'n2val'},<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>success:function(returnData){<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>$("#idd").val(returnData);<wbr><wbr><wbr><wbr><wbr><wbr><wbr><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>}<wbr><wbr><wbr><wbr><wbr><wbr><wbr><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>});<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>});<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>});<br><wbr>&lt;/script&gt;</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></span><br> &lt;/head&gt;<br><wbr>&lt;body&gt;<br><wbr><wbr><wbr>&lt;input type="text" id="idd"&gt;<br><wbr><wbr><wbr>&lt;input type="button" id="buid" value="提交"/&gt;<br><wbr>&lt;/body&gt;<br> &lt;/html&gt;</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr></wbr>

服务器端servlet

<wbr></wbr>

package com.ser;

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 Ser extends HttpServlet {

<wbr><wbr><wbr>public void doGet(HttpServletRequest request, HttpServletResponse response)<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>throws ServletException, IOException {</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr><wbr><wbr><wbr><wbr><wbr><wbr>response.setContentType("text/html;charset=utf-8");<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>request.setCharacterEncoding("utf-8");<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>PrintWriter out = response.getWriter();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>String n1 = request.getParameter("n1");<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>String n2 = request.getParameter("n2");<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>out.print(n1+n2);<br><wbr><wbr><wbr>}</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr><wbr><wbr>public void doPost(HttpServletRequest request, HttpServletResponse response)<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>throws ServletException, IOException {</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr><wbr><wbr><wbr><wbr><wbr><wbr>this.doGet(request, response);<br><wbr><wbr><wbr>}</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

}

你可能感兴趣的:(jquery)