【发布时间】:2018-04-11 06:47:22
【问题描述】:
我正在做一个只使用 JSP、Servlet、Mysql 和 Jquery 的应用程序。我想显示一条来自 Jquery 的错误消息,该消息设置为 json 对象(在 servlet 中)。 在这里我附上了我的代码
-
JSP/Jquery
$("#submitbtn").click(function() { $.ajax({ type : 'GET', url : 'createaction', data : { code : document.getElementById("code").value, descr : document.getElementById("descr").value, checkboxVal : "create" }, success : function(responseText) { alert(responseText); } }); -
小服务程序
JSONObject json = new JSONObject(); String chkVal = request.getParameter("checkboxVal"); if (chkVal.equals("create")){ try { create(request, response); } catch (Exception e) { e.printStackTrace(); try { json.put("error", e); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } response.setContentType("application/json"); response.getWriter().write(json.toString()); System.out.println("aaaaaaaaaaaa"); } }
这里我尝试向前端显示sqlexception(作为测试)..请帮助我..
提前谢谢..!
【问题讨论】:
标签: jquery ajax jsp servlet-3.0