D:\Sam\InterviewsMaterial\SiteWorx\SiteWorxTest\src\java\servelt\SiteWorxFormServlet_P2.java |
1
2
3
4
5 package servelt;
6
7 import bo.StoreUserOutputDataObjectBO;
8 import constants.Constants;
9 import dataobjects.UserOutputDAO;
10 import java.io.IOException;
11 import java.io.PrintWriter;
12 import javax.servlet.ServletException;
13 import javax.servlet.annotation.WebServlet;
14 import javax.servlet.http.HttpServlet;
15 import javax.servlet.http.HttpServletRequest;
16 import javax.servlet.http.HttpServletResponse;
17
18
19
20 @author
21
22 import utils.*;
23 import constants.*;
24 import dataobjects.*;
25 import bo.*;
26
27
28 @WebServlet(name = "SiteWorxFormServlet_P2", urlPatterns = {"/SiteWorxFormServlet_P2"})
29 public class SiteWorxFormServlet_P2 extends HttpServlet
30 {
31
32
33
34 Handles the HTTP
35 <code>GET</code> method.
36
37 @param
38 @param
39 @throws
40 @throws
41
42 @Override
43 protected void doGet(HttpServletRequest request, HttpServletResponse response)
44 throws ServletException, IOException
45 {
46 doPost(request, response);
47 }
48
49
50 Handles the HTTP
51 <code>POST</code> method.
52
53 @param
54 @param
55 @throws
56 @throws
57
58 @Override
59 protected void doPost(HttpServletRequest request, HttpServletResponse response)
60 throws ServletException, IOException
61 {
62 response.setContentType("text/html");
63 PrintWriter out = response.getWriter();
64 out.println("<h2> SiteWorxFormServlet Part 2</h2>");
65 out.println("<BR><BR>");
66
67 UserDigitsInputDAO localUserDigitsInputDAO = new UserDigitsInputDAO();
68
69 String firstName = (String)request.getParameter(Constants.USER_FIRST_NAME_STRING);
70 if(firstName != null)
71 {
72 localUserDigitsInputDAO.setUserFirstName(firstName);;
73 }
74 String lastName = (String)request.getParameter(Constants.USER_LAST_NAME_STRING);
75 if(lastName != null)
76 {
77 localUserDigitsInputDAO.setUserLastName(lastName);
78 }
79 String userID = (String)request.getParameter(Constants.USER_ID_NUMBER_STRING);
80 if(userID != null)
81 {
82 try
83 {
84 long tempLong = Long.parseLong(userID);
85 localUserDigitsInputDAO.setUserID(tempLong);
86 }
87 catch(NumberFormatException e)
88 {
89 localUserDigitsInputDAO.setUserID(Constants.NO_VALUE);
90 }
91 }
92 String userEmail = (String)request.getParameter(Constants.USER_EMAIL_ADDRESS_STRING);
93 if(userEmail != null)
94 {
95 localUserDigitsInputDAO.setUserEmailAddress(userEmail);
96 }
97 String stringOfDigits = (String)request.getParameter(Constants.STRING_OF_DIGITS);
98 if(stringOfDigits != null)
99 {
100 localUserDigitsInputDAO.setStringOfDigits(stringOfDigits);
101 }
102 else
103 stringOfDigits = "";
104
105 Calc_StoreUserDigitsInputDataObjectBO localCalc_StoreUserDigitsInputDataObjectBO
106 = new Calc_StoreUserDigitsInputDataObjectBO(localUserDigitsInputDAO);
107 int totalCount = localCalc_StoreUserDigitsInputDataObjectBO.getTotalCount();
108 long sumValue = localCalc_StoreUserDigitsInputDataObjectBO.getSumValue();
109 double averageValue = localCalc_StoreUserDigitsInputDataObjectBO.getAverageValue();
110 double medianValue = localCalc_StoreUserDigitsInputDataObjectBO.getMedianValue();
111 int highestValue = localCalc_StoreUserDigitsInputDataObjectBO.getHighestValue();
112 int lowestValue = localCalc_StoreUserDigitsInputDataObjectBO.getLowestValue();
113
114 out.println("<BR> ============================================");
115 out.println("<BR> User Data is stored in our Database");
116 out.println("Input values = " + stringOfDigits + "<BR>");
117 out.println("TotalCount = " + totalCount + "<BR>");
118 out.println("sumValue = " + sumValue + "<BR>");
119 out.println("averageValue = " + averageValue + "<BR>");
120 out.println("medianValue = " + medianValue + "<BR>");
121 out.println("highestValue = " + highestValue + "<BR>");
122 out.println("lowestValue = " + lowestValue + "<BR>");
123 out.println("<BR> Thanks for using our service<BR>");
124 out.println("<BR> ============================================");
125 out.flush();
126 out.close();
127
128 }
129
130
131 Returns a short description of the servlet.
132
133 @return
134
135 @Override
136 public String getServletInfo()
137 {
138 return "Short description: SiteWorxFormServlet";
139 }
140 }
141