KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > servlets > Multiply


1 /*
2  * Multiply.java
3  *
4  * Created on 07 January 2005, 16:11
5  */

6
7 package org.netbeans.test.servlets;
8
9 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, HttpServletResponse response)
27     throws ServletException, IOException {
28         response.setContentType("text/html");
29         PrintWriter out = response.getWriter();
30         out.println("<html>");
31         out.println("<head>");
32         out.println("<title>Servlet Multiply</title>");
33         out.println("</head>");
34         out.println("<body>");
35         out.println("<h1>Servlet Multiply at " + request.getContextPath () + "</h1>");
36         
37         org.netbeans.test.freeformlib.Multiplier m = new org.netbeans.test.freeformlib.Multiplier();
38         try {
39             String JavaDoc attributeX = request.getParameter("x");
40             if (attributeX == null) {
41                 attributeX = "";
42             }
43             m.setX(Double.parseDouble(attributeX));
44         } catch(NumberFormatException JavaDoc e) {
45         }
46         try {
47             String JavaDoc attributeY = request.getParameter("y");
48             if (attributeY == null) {
49                 attributeY = "";
50             }
51             m.setY(Double.parseDouble(attributeY));
52         } catch(NumberFormatException JavaDoc e) {
53         }
54         
55         out.println("" + m.getX() + " * " + m.getY() + " = " + m.getMultiplication());
56         
57         out.println("<br/>");
58         out.println("<a HREF=\"index.jsp\">Go back to index.jsp</a>");
59         out.println("</body>");
60         out.println("</html>");
61         out.close();
62     }
63     
64     // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
65
/** Handles the HTTP <code>GET</code> method.
66      * @param request servlet request
67      * @param response servlet response
68      */

69     protected void doGet(HttpServletRequest request, HttpServletResponse response)
70     throws ServletException, IOException {
71         processRequest(request, response);
72     }
73     
74     /** Handles the HTTP <code>POST</code> method.
75      * @param request servlet request
76      * @param response servlet response
77      */

78     protected void doPost(HttpServletRequest request, HttpServletResponse response)
79     throws ServletException, IOException {
80         processRequest(request, response);
81     }
82     
83     /** Returns a short description of the servlet.
84      */

85     public String JavaDoc getServletInfo() {
86         return "Short description";
87     }
88     // </editor-fold>
89
}
90
Popular Tags