Guest User

Untitled

a guest
May 23rd, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.21 KB | None | 0 0
  1. /*
  2. * Echo3Form.java
  3. *
  4. * Created on 17 oktober 2008, 13:04
  5. */
  6.  
  7. import eskuel.CMI_SQL;
  8. import java.io.*;
  9.  
  10. import javax.servlet.*;
  11. import javax.servlet.http.*;
  12.  
  13. /**
  14. *
  15. * @author cmi0814147
  16. * @version
  17. */
  18.  
  19. public class Echo3Form extends HttpServlet {
  20.  
  21. /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
  22. * @param request servlet request
  23. * @param response servlet response
  24. */
  25.  
  26. protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  27. throws ServletException, IOException {
  28. response.setContentType("text/html;charset=UTF-8");
  29. PrintWriter out = response.getWriter();
  30. String template =
  31. "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n"+
  32. "<HTML>\n"+
  33. " <HEAD>\n"+
  34. " <TITLE>Example html forms - 6</TITLE>\n"+
  35. " <META http-equiv=Content-Type content=\"text/html; charset=iso-8859-1\">\n"+
  36. " </HEAD>\n"+
  37. " <BODY text=#000000 bgColor=#ffffff>\n"+
  38. " <TABLE width=480 align=center border=0>\n"+
  39. " <TBODY>\n"+
  40. " <TR>\n"+
  41. " <TD colSpan=2 height=592>\n"+
  42. " <H2>Fill-Out Form Example #6 </H2>This is another fill-out form example, \n"+
  43. " demonstrating multiple independent fill-out forms in the same document. \n"+
  44. " <P>\n"+
  45. " <P>\n"+
  46. " <FORM action=Echo2Form method=post>This is the first form: \n"+
  47. " <P>A text entry field: <INPUT id=\"id_0\" name=entry1> \n"+
  48. " <P>A second text entry field: <INPUT id=\"id_1\" size=10 name=entry2> \n"+
  49. " <P>To submit the query, press this button: <INPUT id=\"id_2\" type=submit value=\"Submit Query\"> \n"+
  50. " <P>To clear the form, press this button: <INPUT id=\"id_3\" type=reset value=\"Clear Form\"> </FORM>\n"+
  51. " <P>\n"+
  52. " <FORM action=Echo3Form method=post>This is a <B>completely different</B> \n"+
  53. " form from the one right above. \n"+
  54. " <P>Here's three checkboxes right in a row: \n"+
  55. " <P>\n"+
  56. " <OL>\n"+
  57. " <LI><INPUT id=\"id_4\" type=checkbox name=box1> The first checkbox \n"+
  58. " <LI><INPUT id=\"id_5\" type=checkbox name=box2> The second checkbox \n"+
  59. " <LI><INPUT id=\"id_6\" type=checkbox name=box3> The third checkbox </LI></OL>And a \n"+
  60. " text entry form: <INPUT id=\"id_7\" size=30 name=entry6> \n"+
  61. " <P>To submit the query, press this button: <INPUT id=\"id_8\" type=submit value=\"Submit Query2\"> \n"+
  62. " <P>To clear the form, press this button: <INPUT id=\"id_9\" type=reset value=\"Clear Form\"> \n"+
  63. " </FORM>\n"+
  64. " </P>\n"+
  65. " </TD>\n"+
  66. " </TR>\n"+
  67. " </TBODY>\n"+
  68. " </TABLE>\n"+
  69. " </BODY>\n"+
  70. "</HTML>\n";
  71.  
  72. String output = template;
  73. String error = " ";
  74.  
  75. //2e form
  76. String box1 = request.getParameter("box1"); //checked
  77. String box2 = request.getParameter("box2"); //checked
  78. String box3 = request.getParameter("box3"); //checked
  79. String entry6 = request.getParameter("entry6");
  80.  
  81. if (entry6.equals("")) {
  82. error += "<br> entry6";
  83. }
  84.  
  85. //2e form
  86. output = output.replace("<INPUT id=\"id_4\" name=box1", "<INPUT id=\"id_4\" name=box1 value = " + box1);
  87. output = output.replace("<INPUT id=\"id_5\" name=box2", "<INPUT id=\"id_5\" name=box2 value = " + box2);
  88. output = output.replace("<INPUT id=\"id_6\" name=box3", "<INPUT id=\"id_6\" name=box3 value = " + box3);
  89. output = output.replace("<INPUT id=\"id_7\" name=entry6", "<INPUT id=\"id_7\" name=entry6 value = " + entry6);
  90.  
  91.  
  92. if (error.length()>0) out.println("missing: "+error);
  93.  
  94. else {
  95. out.println("Uw gegevens worden verwerkt");
  96. CMI_SQL sql = new CMI_SQL("jdbc:mysql://mysql.cmi-hro.nl:3306/cmi0814147","cmi0814147","q7zm3hvx");
  97. String Query = "insert into form4( box1, box2, box3, entry6) values('"+box1+"','"+box2+"','"+box3+"','"+entry6+"')";
  98. sql.insertQuery(Query);
  99.  
  100. }
  101. out.close();
  102. }
  103.  
  104. // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  105. /** Handles the HTTP <code>GET</code> method.
  106. * @param request servlet request
  107. * @param response servlet response
  108. */
  109. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  110. throws ServletException, IOException {
  111. processRequest(request, response);
  112. }
  113.  
  114. /** Handles the HTTP <code>POST</code> method.
  115. * @param request servlet request
  116. * @param response servlet response
  117. */
  118. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  119. throws ServletException, IOException {
  120. processRequest(request, response);
  121. }
  122.  
  123. /** Returns a short description of the servlet.
  124. */
  125. public String getServletInfo() {
  126. return "Short description";
  127. }
  128. // </editor-fold>
  129. }
Add Comment
Please, Sign In to add comment