1 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 20 public class Multiply extends HttpServlet { 21 22 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 attributeX = request.getParameter("x"); 40 if (attributeX == null) { 41 attributeX = ""; 42 } 43 m.setX(Double.parseDouble(attributeX)); 44 } catch(NumberFormatException e) { 45 } 46 try { 47 String attributeY = request.getParameter("y"); 48 if (attributeY == null) { 49 attributeY = ""; 50 } 51 m.setY(Double.parseDouble(attributeY)); 52 } catch(NumberFormatException 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 69 protected void doGet(HttpServletRequest request, HttpServletResponse response) 70 throws ServletException, IOException { 71 processRequest(request, response); 72 } 73 74 78 protected void doPost(HttpServletRequest request, HttpServletResponse response) 79 throws ServletException, IOException { 80 processRequest(request, response); 81 } 82 83 85 public String getServletInfo() { 86 return "Short description"; 87 } 88 } 90 | Popular Tags |