-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCarChoiceServlet.java
More file actions
77 lines (65 loc) · 2.49 KB
/
CarChoiceServlet.java
File metadata and controls
77 lines (65 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package servletPackage;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Automobile;
import adapter.BuildAuto;
public class CarChoiceServlet extends HttpServlet {
private BuildAuto buildAuto = null;
@Override
public void init() throws ServletException {
// Servlet initialization code here
super.init();
buildAuto = new BuildAuto();
}
@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// Set response content type
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String model = request.getParameter("model");
Automobile automobile = buildAuto.getAuto(model);
out.println("<head><style>");
out.println("table, th, td { border: 1px solid black; }");
out.println("</style></head>");
out.println("<form action=\"/CIS_35B_-_Lab06/totalcost\">");
out.println("<table>");
out.println("<tr>");
out.println("<th>Make/Model</th>");
out.println("<td>");
out.println("<select name=\"model\">");
out.println("<option value=\"" + model + "\">" + model + "</option>");
out.println("</select");
out.println("</td>");
out.println("</tr>");
int numOpsets = automobile.getNumOpsets();
for (int i = 0; i < numOpsets; ++i) {
String opsetName = automobile.getOpsetName(i);
ArrayList<String> optNames = automobile.getOpsetOptNames(i);
out.println("<tr>");
out.println("<th>" + opsetName + "</th>");
out.println("<td>");
out.println("<select name=\"" + opsetName.toLowerCase() + "\">>");
for (int j = 0; j < optNames.size(); ++j) {
out.println("<option value=\"" + optNames.get(j) + "\">"
+ optNames.get(j) + "</option>");
}
out.println("</select");
out.println("</td>");
out.println("</tr>");
}
out.println("</table>");
out.println("<input type=\"submit\" value=\"Done\">");
out.println("</form>");
}
@Override
public void destroy() {
// resource release
super.destroy();
}
}