日期:2014-05-16 浏览次数:20542 次
两数相加:
ajax.jsp
?
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript" src="scripts/jquery-1.3.1.js"></script>
<script>
? $(function(){
? $("#button").click(function(){
? $.ajax({
? type:"post",
? url:"MyServlet",
? dateType:"html",
? data:{"param1":$("#param1").val(),"param2":$("#param2").val()},
? success:function(returnedData){
? $("#result").val(returnedData);
? }
? });
? })
? })
? </script>
</head>
<body>
<input type="text" id="param1"></input>+
<input type="text" id="param2"></input>=
<input type="text" id="result"></input>
<input type="button" value="get" />
</body>
</html>
?
处理的servlet
?
package com.sun;
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.HttpServletRespo