Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Echo3Form.java
- *
- * Created on 17 oktober 2008, 13:04
- */
- import eskuel.CMI_SQL;
- import java.io.*;
- import javax.servlet.*;
- import javax.servlet.http.*;
- /**
- *
- * @author cmi0814147
- * @version
- */
- public class Echo3Form extends HttpServlet {
- /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
- * @param request servlet request
- * @param response servlet response
- */
- protected void processRequest(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- response.setContentType("text/html;charset=UTF-8");
- PrintWriter out = response.getWriter();
- String template =
- "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n"+
- "<HTML>\n"+
- " <HEAD>\n"+
- " <TITLE>Example html forms - 6</TITLE>\n"+
- " <META http-equiv=Content-Type content=\"text/html; charset=iso-8859-1\">\n"+
- " </HEAD>\n"+
- " <BODY text=#000000 bgColor=#ffffff>\n"+
- " <TABLE width=480 align=center border=0>\n"+
- " <TBODY>\n"+
- " <TR>\n"+
- " <TD colSpan=2 height=592>\n"+
- " <H2>Fill-Out Form Example #6 </H2>This is another fill-out form example, \n"+
- " demonstrating multiple independent fill-out forms in the same document. \n"+
- " <P>\n"+
- " <P>\n"+
- " <FORM action=Echo2Form method=post>This is the first form: \n"+
- " <P>A text entry field: <INPUT id=\"id_0\" name=entry1> \n"+
- " <P>A second text entry field: <INPUT id=\"id_1\" size=10 name=entry2> \n"+
- " <P>To submit the query, press this button: <INPUT id=\"id_2\" type=submit value=\"Submit Query\"> \n"+
- " <P>To clear the form, press this button: <INPUT id=\"id_3\" type=reset value=\"Clear Form\"> </FORM>\n"+
- " <P>\n"+
- " <FORM action=Echo3Form method=post>This is a <B>completely different</B> \n"+
- " form from the one right above. \n"+
- " <P>Here's three checkboxes right in a row: \n"+
- " <P>\n"+
- " <OL>\n"+
- " <LI><INPUT id=\"id_4\" type=checkbox name=box1> The first checkbox \n"+
- " <LI><INPUT id=\"id_5\" type=checkbox name=box2> The second checkbox \n"+
- " <LI><INPUT id=\"id_6\" type=checkbox name=box3> The third checkbox </LI></OL>And a \n"+
- " text entry form: <INPUT id=\"id_7\" size=30 name=entry6> \n"+
- " <P>To submit the query, press this button: <INPUT id=\"id_8\" type=submit value=\"Submit Query2\"> \n"+
- " <P>To clear the form, press this button: <INPUT id=\"id_9\" type=reset value=\"Clear Form\"> \n"+
- " </FORM>\n"+
- " </P>\n"+
- " </TD>\n"+
- " </TR>\n"+
- " </TBODY>\n"+
- " </TABLE>\n"+
- " </BODY>\n"+
- "</HTML>\n";
- String output = template;
- String error = " ";
- //2e form
- String box1 = request.getParameter("box1"); //checked
- String box2 = request.getParameter("box2"); //checked
- String box3 = request.getParameter("box3"); //checked
- String entry6 = request.getParameter("entry6");
- if (entry6.equals("")) {
- error += "<br> entry6";
- }
- //2e form
- output = output.replace("<INPUT id=\"id_4\" name=box1", "<INPUT id=\"id_4\" name=box1 value = " + box1);
- output = output.replace("<INPUT id=\"id_5\" name=box2", "<INPUT id=\"id_5\" name=box2 value = " + box2);
- output = output.replace("<INPUT id=\"id_6\" name=box3", "<INPUT id=\"id_6\" name=box3 value = " + box3);
- output = output.replace("<INPUT id=\"id_7\" name=entry6", "<INPUT id=\"id_7\" name=entry6 value = " + entry6);
- if (error.length()>0) out.println("missing: "+error);
- else {
- out.println("Uw gegevens worden verwerkt");
- CMI_SQL sql = new CMI_SQL("jdbc:mysql://mysql.cmi-hro.nl:3306/cmi0814147","cmi0814147","q7zm3hvx");
- String Query = "insert into form4( box1, box2, box3, entry6) values('"+box1+"','"+box2+"','"+box3+"','"+entry6+"')";
- sql.insertQuery(Query);
- }
- out.close();
- }
- // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
- /** Handles the HTTP <code>GET</code> method.
- * @param request servlet request
- * @param response servlet response
- */
- protected void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- processRequest(request, response);
- }
- /** Handles the HTTP <code>POST</code> method.
- * @param request servlet request
- * @param response servlet response
- */
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- processRequest(request, response);
- }
- /** Returns a short description of the servlet.
- */
- public String getServletInfo() {
- return "Short description";
- }
- // </editor-fold>
- }
Add Comment
Please, Sign In to add comment