01: /*
02: * Multiply.java
03: *
04: * Created on 07 January 2005, 16:11
05: */
06:
07: package org.netbeans.test.servlets;
08:
09: import java.io.*;
10: import java.net.*;
11:
12: import javax.servlet.*;
13: import javax.servlet.http.*;
14:
15: /**
16: *
17: * @author Administrator
18: * @version
19: */
20: public class Multiply extends HttpServlet {
21:
22: /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
23: * @param request servlet request
24: * @param response servlet response
25: */
26: protected void processRequest(HttpServletRequest request,
27: HttpServletResponse response) throws ServletException,
28: IOException {
29: response.setContentType("text/html");
30: PrintWriter out = response.getWriter();
31: out.println("<html>");
32: out.println("<head>");
33: out.println("<title>Servlet Multiply</title>");
34: out.println("</head>");
35: out.println("<body>");
36: out.println("<h1>Servlet Multiply at "
37: + request.getContextPath() + "</h1>");
38:
39: org.netbeans.test.freeformlib.Multiplier m = new org.netbeans.test.freeformlib.Multiplier();
40: try {
41: String attributeX = request.getParameter("x");
42: if (attributeX == null) {
43: attributeX = "";
44: }
45: m.setX(Double.parseDouble(attributeX));
46: } catch (NumberFormatException e) {
47: }
48: try {
49: String attributeY = request.getParameter("y");
50: if (attributeY == null) {
51: attributeY = "";
52: }
53: m.setY(Double.parseDouble(attributeY));
54: } catch (NumberFormatException e) {
55: }
56:
57: out.println("" + m.getX() + " * " + m.getY() + " = "
58: + m.getMultiplication());
59:
60: out.println("<br/>");
61: out.println("<a href=\"index.jsp\">Go back to index.jsp</a>");
62: out.println("</body>");
63: out.println("</html>");
64: out.close();
65: }
66:
67: // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
68: /** Handles the HTTP <code>GET</code> method.
69: * @param request servlet request
70: * @param response servlet response
71: */
72: protected void doGet(HttpServletRequest request,
73: HttpServletResponse response) throws ServletException,
74: IOException {
75: processRequest(request, response);
76: }
77:
78: /** Handles the HTTP <code>POST</code> method.
79: * @param request servlet request
80: * @param response servlet response
81: */
82: protected void doPost(HttpServletRequest request,
83: HttpServletResponse response) throws ServletException,
84: IOException {
85: processRequest(request, response);
86: }
87:
88: /** Returns a short description of the servlet.
89: */
90: public String getServletInfo() {
91: return "Short description";
92: }
93: // </editor-fold>
94: }
|