/Users/lyon/j4p/src/net/server/servlets/HelloWorldExample.java
|
1 package net.server.servlets;
2 //
3 // uid = cr32001
4 // pw = Fall2003
5
6 import javax.servlet.ServletException;
7 import javax.servlet.http.HttpServlet;
8 import javax.servlet.http.HttpServletRequest;
9 import javax.servlet.http.HttpServletResponse;
10 import java.io.IOException;
11 import java.io.PrintWriter;
12
13 public class HelloWorldExample extends HttpServlet {
14
15
16 public static String getForm() {
17 return
18 "<HTML>"
19 + "<HEAD>"
20 + "<TITLE>Phone Book</TITLE></HEAD>"
21 + "<BODY>"
22 + "<CENTER>"
23 + "<H1>Telephone Book</H1>"
24 + "<FORM ACTION=HelloWorldExample METHOD=GET><TABLE>"
25 + "<TR>"
26 + " <TD>Last Name</TD>"
27 + " <TD><INPUT TYPE=TEXT SIZE=20 NAME=lastname></TD></TR><TR>"
28 + " <TD>Middle Name</TD>"
29 + " <TD><INPUT TYPE=TEXT SIZE=20 NAME=middlename></TD></TR><TR>"
30 + " <TD>First Name</TD>"
31 + " <TD><INPUT TYPE=TEXT SIZE=20 NAME=firstname></TD></TR><TR>"
32 + " <TD>address1</TD>"
33 + " <TD><INPUT TYPE=TEXT SIZE=20 NAME=address1></TD></TR><TR>"
34 + " <TD>address2</TD>"
35 + " <TD><INPUT TYPE=TEXT SIZE=20 NAME=address2></TD></TR><TR>"
36 + " <TD>Phone1</TD>"
37 + " <TD><INPUT TYPE=TEXT SIZE=20 NAME=phone1></TD></TR>"
38 + " <TD>Phone2</TD>"
39 + " <TD><INPUT TYPE=TEXT SIZE=20 NAME=phone2></TD></TR>"
40 + " <TD>Phone3</TD>"
41 + " <TD><INPUT TYPE=TEXT SIZE=20 NAME=phone3></TD></TR>"
42 + "</TABLE>"
43 + "<INPUT TYPE=Submit NAME=Add VALUE=Add New Entry>"
44 + "<INPUT TYPE=Reset VALUE=Reset>"
45 + "</FORM><BR>"
46 + "</BODY></HTML>";
47 }
48
49 public void doGet(HttpServletRequest request,
50 HttpServletResponse response)
51 throws IOException, ServletException {
52 response.setContentType("text/html");
53 PrintWriter out = response.getWriter();
54 String fn = request.getParameter("firstname");
55 String mn = request.getParameter("middlename");
56 String ln = request.getParameter("lastname");
57 String a1 = request.getParameter("address1");
58 String a2 = request.getParameter("address2");
59 String p1 = request.getParameter("phone1");
60 String p2 = request.getParameter("phone2");
61 String p3 = request.getParameter("phone3");
62 out.println("<html>");
63 out.println("<body bgcolor=\"white\">");
64 out.println("<body>");
65 if (fn != null) {
66 String sql = Execute.getSql(fn, mn, ln, a1, a2, p1, p2, p3);
67 out.println("sql inserted=" + sql);
68 Execute.statement(sql);
69 } else
70 out.println(getForm());
71
72 out.println("</body>");
73 out.println("</html>");
74 }
75 }
76
77
78
79