//JavaScript
function verify(){
//用JQuery语法,利用id得到对应的JQuery对象。
var jqObj = $("#inputext");
//获取对象中的值。
var value = jqObj.val();
//使用get的方式将数据传的服务器,callback是服务器端数据返回后运行的回调函数名
$.get("servlet/Test?inputext=" + value,null,callback);
}
//定义回调函数,data用于接收服务器端返回的数据
function callback(data){
//得到页面中的div对象
var divobj = $("#div");
//将返回的数据更新到div中
divobj.html(data);
}
package com.fenghuo.test;
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 Test extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String data = request.getParameter("inputext");
//此处只是将数据做了简单的处理
if(data == null || data.equals("")){
out.write("未得到数据或数据为空!");
}else{
out.write("已接收数据数据:"+data);
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}