欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

javaweb中ajax请求后台servlet(实例)

程序员文章站 2024-02-13 13:04:22
废话不多说,直接上代码 public class dzfp_jdbc extends httpservlet{ private static final l...

废话不多说,直接上代码

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("网络异常,请稍后重试");

  } 
});

<servlet>
  <servlet-name>dzfp_jdbc</servlet-name>
  <servlet-class>
  weishijiestudio.hangxinwx.servlet.dzfp_jdbc
  </servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>dzfp_jdbc</servlet-name>
  <url-pattern>/dzfp_jdbc</url-pattern>
</servlet-mapping>

以上这篇javaweb中ajax请求后台servlet(实例)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。