Home > Java > Java Tutorial > body text

Sample code sharing of how ajax requests background servlet in javaweb

黄舟
Release: 2017-06-04 09:29:22
Original
2004 people have browsed it

The following editor will bring you an article about ajax request background in javawebservlet(example). The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor and take a look.

No more nonsense, just go to the code

public class DZFP_jdbc extends HttpServlet{
  private static final long serialVersionUID = 1L;

  public static Connection conn; 
  public static ResultSet rs = null ;  
  public static PreparedStatement ps = null ;
  private static String url = "jdbc:oracle:thin:@192.168.100.11:1111:CRM";
  private static String name = "name";
  private static String pwd = "pwd";

  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    /*PreparedStatement ps;
    ResultSet rs = null;*/
    response.setCharacterEncoding("utf-8");
    request.setCharacterEncoding("utf-8");
    response.setHeader("content-type", "text/html;charset=UTF-8");

    PrintWriter out = response.getWriter();

    ***********

    out.print("{\"errorno\":[{\"list\":error}]}");
  }
}


$.ajax({ 
  type: "post", 
  url: "DZFP_jdbc", 
  dataType: "text", 

    data : {
      taxcode : taxcode,
      mobilenum : mobilenum
  },
  timeout : 50000,

    success: function (data) { 
  var jsonobjs = eval("(" + data + ")");
  var list = jsonobjs.errorno[0].list;


    }, 
  error: function() {
      alert("网络异常,请稍后重试");

  } 
});


  DZFP_jdbc
  
  weishijiestudio.hangxinwx.servlet.DZFP_jdbc
  


  DZFP_jdbc
  /DZFP_jdbc
Copy after login

The above is the detailed content of Sample code sharing of how ajax requests background servlet in javaweb. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!