01 <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*"  errorPage="" %>
02 <html>
03 <head>
04 <title>.: Pizza :.</title>
05 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
06 </head>
07 
08 <body>
09 <%!
10   public void sendBestellung(String sql) {
11     try {
12       Class.forName("com.mysql.jdbc.Driver");
13       Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/project""root""");
14       Statement stmt = conn.createStatement();
15       stmt.executeUpdate(sql);
16       if (conn != null) {
17         conn.close();
18       }    
19     catch (Exception exc){}
20   }
21 %>
22 
23 <%
24   String id_pizza = request.getParameter"pizza" );
25   String anzahl = request.getParameter"anzahl" );
26   if id_pizza == null || anzahl == null) {
27 %>
28 <h1>PIZZA-Service</h1>
29 <h3>Ihre Bestellung..</h3><br>
30     
31     
32 <form action="index2.jsp" method="post" name target="_self" onSubmit="">
33   <select name="pizza">
34         <%
35         // load driver
36         Class.forName("com.mysql.jdbc.Driver");
37         Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/project""root""");
38         // create statement-object
39         Statement stmt = conn.createStatement();
40         ResultSet rs = stmt.executeQuery("SELECT id, name, preis FROM pizza_type");
41         // data
42         while (rs.next()) {  
43           out.print("<option value='");
44           out.print(rs.getObject(1));
45           out.println("'>");
46           out.print(rs.getObject(2"  (" + rs.getObject(3" € ) ");
47           out.println("</option>");
48         }
49         A;if (conn != null) {
50           conn.close();
51         }
52         
53         %>
54       </select>
55       <select name="anzahl">
56         <option>1</option>
57         <option>2</option>
58         <option>3</option>
59   A      <option>4</option>
60         <option>5</option>
61       </select>
62       <input name="absenden" type="submit" value="absenden">
63     </form>
64     
65 <%
66   else {
67     String sql = "INSERT INTO bestellung values ('', " + id_pizza  + ", " + anzahl + ")";
68  &nbsAp;  sendBestellung(sql);
69     
70     out.println("Ihre Bestellung wurde weitergeleitet...<br>");
71     out.println("<a href='index2.jsp'>..neue Bestellung</a>");
72   }
73 %>
74 
75 
76 
77 
78 
79 </html>