作者:欢乐乡村烤鸭8321 | 来源:互联网 | 2024-09-25 17:16
java代码packageaction;importjava.io.IOException;importjava.io.PrintWriter;importjavax.servlet.Serv
java代码
package action;
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;
/**
* Servlet implementation class getAjaxServlet
*/
public class getAjaxServlet extends HttpServlet {
private static final long serialVersiOnUID= 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
response.setCharacterEncoding("utf-8");
String name=request.getParameter("name");
String age=request.getParameter("age");
System.out.println("name:"+name+","+"age:"+age);
PrintWriter out=response.getWriter();
out.println("成功从Servlet拿到数据");
out.flush();
out.close();
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
}
jsp页面:
<%@ page language="java" cOntentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
web.xml
ajax02
index.html
index.htm
index.jsp
default.html
default.htm
ajax.jsp
AjaxServlet
action.getAjaxServlet
AjaxServlet
/ajax.do