jQuery对ajax的支持

jQuery对ajax的支持_第1张图片

示例:




jQuery类库使用演示

   






 
  
       

       
       
       
    

在postServlet中的代码:



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


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


/**
 * Servlet implementation class postServlet
 */
@WebServlet("/postServlet")
public class postServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public postServlet() {
        super();
        // TODO Auto-generated constructor stub
    }


/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
}


/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 request.setCharacterEncoding("utf-8");
String studid=request.getParameter("studid");
String studname=request.getParameter("studname");
String sex=request.getParameter("sex");
String classname=request.getParameter("classname");
System.out.println("studid="+studid+"studname="+studname+"sex="+sex+"classname="+classname);
response.setContentType("text/html;charset=utf-8");
PrintWriter out=response.getWriter();
out.println("新增成功");
out.flush();
out.close();
}


}






















你可能感兴趣的:(java)