json格式ajax的post请求方式

1.java代码如下:
packagecom.eduask;
importjava.io.IOException;
importjavax.servlet.ServletException;
importjavax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
publicclassDemo5extendsHttpServlet{
@Override
【json格式ajax的post请求方式】 protectedvoidservice(HttpServletRequest req, HttpServletResponse resp)
throwsServletException, IOException {
resp.setContentType("text/xml; charset=utf-8");
String name=req.getParameter("username1");
resp.setCharacterEncoding("utf-8");
String msg="";
if("tom".equals(name)) {
msg="{'msg':'failed'}";
resp.getWriter().write(msg);
}else{
msg="{'msg':'success'}";
resp.getWriter().write(msg);
}
}
}
2.json.jsp代码如下:


username1:"text"id="username1"name="username1">
"msg1">


3.web.xml配置文件如下:


Demo5
com.eduask.Demo5


Demo5
/Demo5

    推荐阅读