首頁  >  文章  >  Java  >  javaweb中ajax如何請求後台servlet的範例程式碼分享

javaweb中ajax如何請求後台servlet的範例程式碼分享

黄舟
黄舟原創
2017-06-04 09:29:222145瀏覽

下面小編就為大家帶來一篇javaweb中ajax請求後台servlet(實例)。小編覺得蠻不錯的,現在就分享給大家,也給大家做個參考。一起跟著小編過來看看吧

廢話不多說,直接上程式碼

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的範例程式碼分享的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn