<!DOCTYPEhtml><html><head><metacharset="UTF-8"><title>Insert title here</title><scriptsrc="js/jquery1.11.3.min.js"></script><scriptsrc="js/form.js"></script></head><body><formid="regForm"action=""method="post">用户名:<inputtype="text"name="uname"/>密码:<inputtype="password"name='pwd'/><inputtype='button'name='sub'value='提交'/></form></body></html>
servlet
packagecom.wowowo.ajax;importjava.io.IOException;importjava.io.PrintWriter;importjavax.servlet.ServletException;importjavax.servlet.annotation.WebServlet;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;/*** Servlet implementation class FormServlet*/@WebServlet("/FormServlet")publicclassFormServletextendsHttpServlet{privatestaticfinallong serialVersionUID =1L;/*** @see HttpServlet#HttpServlet()*/publicFormServlet(){super();// TODO Auto-generated constructor stub}/*** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)*/protectedvoiddoGet(HttpServletRequest request,HttpServletResponse response)throwsServletException,IOException{// TODO Auto-generated method stub//response.getWriter().append("Served at: ").append(request.getContextPath());request.setCharacterEncoding("utf-8");response.setContentType("text/html;charset=utf-8");PrintWriter out = response.getWriter();String uname=request.getParameter("uname");String pwd=request.getParameter("pwd");out.println("接收到了客户端提交的:"+uname+","+pwd);}/*** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/protectedvoiddoPost(HttpServletRequest request,HttpServletResponse response)throwsServletException,IOException{// TODO Auto-generated method stubdoGet(request, response);}}