javaweb中ajax请求后台servlet(实例)
时间:2020-12-02 13:05:34|栏目:JAVA代码|点击: 次
废话不多说,直接上代码
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>
上一篇:Eclipse 出现A configuration with this name already exists问题解决方法
栏 目:JAVA代码
本文标题:javaweb中ajax请求后台servlet(实例)
本文地址:http://www.codeinn.net/misctech/28688.html
阅读排行
- 1Java Swing组件BoxLayout布局用法示例
- 2java中-jar 与nohup的对比
- 3Java邮件发送程序(可以同时发给多个地址、可以带附件)
- 4Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.Type异常
- 5Java中自定义异常详解及实例代码
- 6深入理解Java中的克隆
- 7java读取excel文件的两种方法
- 8解析SpringSecurity+JWT认证流程实现
- 9spring boot里增加表单验证hibernate-validator并在freemarker模板里显示错误信息(推荐)
- 10深入解析java虚拟机