01 package interval;
02
03 import javax.servlet.*;
04 import javax.servlet.http.*;
05 import java.io.*;
06 import java.util.*;
07
08 public class AnketaServlet extends HttpServlet {
09 private static final String CONTENT_TYPE = "text/html;charset=windows-1250";
10
11 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
12 response.setContentType(CONTENT_TYPE);
13 request.setCharacterEncoding("windows-1250");
14 PrintWriter out = response.getWriter();
15 out.println("<html>");
16 out.println("<head><title>AnketaServlet</title></head>");
17 out.println("<body bgcolor='#CAE4FF'>");
18 out.println("<p>Vážený(á) pán(i) " + request.getParameter("identita")+ ".</p>");
19 out.println("<p>Dozvedeli sme sa že Vám je " + request.getParameter("vek") + " rokov, <br>");
20 out.println("páči sa Vám " + request.getParameter("auto") + ",");
21 out.println("rád(a) si vychutnáte " + request.getParameter("jedlo") + " a <br>");
22 out.println("občas si zájdete na " + request.getParameter("sport") + "</p>");
23 String[] zaluby = request.getParameterValues("zaluby");
24 out.println("<p>K Vašim ostatným záľubám patrí: <br>");
25 out.println("<ul>");
26 if (zaluby != null) {
27 for (int i = 0; i < zaluby.length; i++) {
28 if (zaluby[i].equals("ine")) {
29 out.println("<li>" + request.getParameter("ine_zaluby") + "</li>");
30 }
31 else {
32 out.println("<li>" + zaluby[i] + "</li>");
33 }
34 }
35 }
36 else { out.println("<em>Nezadali ste nič.</em>");}
37 out.println("</ul></p>");
38 out.println("<p>Ďakujeme Vám za učasť v našej ankete.</p>");
39 out.println("<hr>");
40 getRequestInfo(request, out);
41 out.println("</body></html>");
42 }
43
44 public void getRequestInfo(HttpServletRequest req, PrintWriter out) throws ServletException , IOException {
45 out.println("<h4><B>Doplnkové informácie:</b></h4>");
46 out.println("<b>Typ požiadavky:</b> " + req.getMethod() + "<br>");
47 out.println("<b>URI požiadavky:</b> " + req.getRequestURI() + "<br>");
48 out.println("<b>Protokol požiadavky:</b> " + req.getProtocol() + "<br>");
49 out.println("<b>Schéma požiadavky:</b> " + req.getScheme() + "<br>");
50 out.println("<b>Cesta k servletu:</b> " + req.getServletPath() + "<br>");
51 out.println("<b>Znaková sada:</b> " + req.getCharacterEncoding() + "<br>");
52 out.println("<b>Reťazec query:</b> " + req.getQueryString() + "<br>");
53 out.println("<b>Dlžka tela požiadavky:</b> " + req.getContentLength() + "<br>");
54 out.println("<b>MIME typ požiadavky:</b> " + req.getContentType() + "<br>");
55 out.println("<b>Vzdialený user:</b> " + req.getRemoteUser() + "<br>");
56 out.println("<b>Adresa vzdialeného servera:</b> " + req.getRemoteAddr() + "<br>");
57 out.println("<b>Názov vzdialeného servera:</b> " + req.getRemoteHost() + "<br>");
58 out.println("<b>Autorizačná schéma:</b> " + req.getAuthType() + "<br>");
59 }
60 }
|