Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. <%@ page import="java.sql.*"%>
  2. <%@page import="org.json.*"%>
  3. <%
  4. System.out.println("Start");
  5. String value = request.getParameter("jsonData");
  6. JSONObject newObj = new JSONObject();
  7.  
  8. try {
  9. newObj = new JSONObject(request.getParameter("jsonData"));
  10. } catch (JSONException e) {
  11. e.printStackTrace();
  12. }
  13.  
  14. String title = "";
  15. String tag = "";
  16. String postData = "";
  17.  
  18. try {
  19. title = newObj.getJSONObject("mydata").getString("title");
  20. tag = newObj.getJSONObject("mydata").getString("tag");
  21. postData = newObj.getJSONObject("mydata").getString("postData");
  22. } catch (JSONException e) {
  23. e.printStackTrace();
  24. }
  25. try {
  26. Class.forName("com.mysql.jdbc.Driver");
  27. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql?useSSL=true", "root", "1111");
  28. //System.out.println(con);
  29. PreparedStatement ps = con.prepareStatement("insert into forumdb.userpost(title,post,tag) values(?,?,?)");
  30. ps.setString(1, title);
  31. ps.setString(2, postData);
  32. ps.setString(3, tag);
  33. ps.executeUpdate();
  34. con.close();
  35. } catch (Exception e) {
  36. }
  37. System.out.println("End");
  38.  
  39. response.setContentType("text/html");
  40. response.getWriter().write("success");
  41. %>
  42.  
  43.  
  44.  
  45. var request;
  46. function postArticle() {
  47. var title=document.postform.title.value;
  48. var postDescription = CKEDITOR.instances.postDescription.getData();
  49. var tag=document.postform.tag.value;
  50. var myData = {"mydata": {"title": title, "tag": tag, "postData":postDescription}};
  51. $.ajax({
  52. type: "POST",
  53. url: "/forum1/index.jsp",
  54. data: {jsonData: JSON.stringify(myData)},
  55. dataType: "json",
  56. success: function(){
  57. if(success==false)
  58. { location.reload(); }
  59. }
  60. });
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement