533e6e15943bfa79a88f24add07a2d9bf0d28e1c
[proteocache.git] / server / compbio / listeners / LengthServlet.java
1 package compbio.listeners;
2
3 import java.io.IOException;
4 import java.util.Calendar;
5
6 import javax.servlet.RequestDispatcher;
7 import javax.servlet.ServletException;
8 import javax.servlet.annotation.WebServlet;
9 import javax.servlet.http.HttpServlet;
10 import javax.servlet.http.HttpServletRequest;
11 import javax.servlet.http.HttpServletResponse;
12
13 import compbio.statistic.StatisticsProt;
14
15 /**
16  * Servlet implementation class LengthServlet
17  */
18 @WebServlet("/LengthServlet")
19 public class LengthServlet extends HttpServlet {
20         private static final long serialVersionUID = 1L;
21
22         /**
23          * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
24          *      response)
25          */
26         protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
27                 String date1 = request.getParameter("data1");
28                 String date2 = request.getParameter("data2");
29                 StatisticsProt sp = new StatisticsProt();
30                 if (null != request.getParameter("option")) {
31                         Calendar cal = Calendar.getInstance();
32                         date1 = StatisticsProt.DateFormatYYMMDD(sp.earliestDate());
33                         date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH);
34                 }
35                 request.setAttribute("data1", date1);
36                 request.setAttribute("data2", date2);
37                 request.setAttribute("result", sp.readLength(date1, date2));
38                 request.setAttribute("flag", request.getParameter("option"));
39                 RequestDispatcher rd = request.getRequestDispatcher("/ReportLength.jsp");
40                 rd.forward(request, response);
41         }
42
43         /**
44          * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
45          *      response)
46          */
47         protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
48                 doGet(request, response);
49         }
50 }