001 package interval;
002
003 import java.io.*;
004 import javax.servlet.*;
005 import javax.servlet.http.*;
006
007 public class FormManager extends HttpServlet {
008
009 public void doGet(HttpServletRequest req, HttpServletResponse res)
010 throws ServletException, IOException {
011
012 res.setContentType("text/html;charset=windows-1250");
013 PrintWriter out = res.getWriter();
014 // vytvorenie formulara
015 out.println("<html><head><title>Prieskum ...</title></head><body>" +
016 "<table border=\"0\"><tr><td>" +
017 "<p align=\"center\"><u>Jednoduchá anketa</u></p>" +
018 "<form method=\"post\">" +
019 "<fieldset><legend><strong>Osobné údaje</strong></legend>" +
020 "<table cellpadding=\"2\" border=\"0\" cellspacing=\"1\">" +
021 "<tr valign=\"middle\">" +
022 "<td align=\"right\">meno*:</td>" +
023 "<td><input type=\"text\" name=\"name\" class=\"form\" size=\"8\"></td>" +
024 "</tr><tr valign=\"middle\">" +
025 "<td align=\"right\">priezvisko:</td>" +
026 "<td><input type=\"text\" name=\"surname\" class=\"form\" size=\"15\"></td>" +
027 "</tr><tr valign=\"middle\">" +
028 "<td align=\"right\">e-mail*:</td>" +
029 "<td><input type=\"text\" name=\"email\" class=\"form\" size=\"20\"></td>" +
030 "</tr></table></fieldset><fieldset>" +
031 "<legend><strong>Pracovné údaje</strong></legend>" +
032 "<table cellpadding=\"2\" border=\"0\" cellspacing=\"1\">" +
033 "<tr valign=\"middle\">" +
034 "<td align=\"right\">pracovné* <br> zaradenie:</td>" +
035 "<td valign=\"bottom\">" +
036 "<input type=\"text\" name=\"job\" class=\"form\" size=\"30\"></td>" +
037 "</tr><tr valign=\"top\">" +
038 "<td align=\"right\">Aké <br> nástroje <br> využívate:</td><td >" +
039 "<input type=\"checkbox\" name=\"tools\" value=\"NetBeans\"> NetBeans <br>" +
040 "<input type=\"checkbox\" name=\"tools\" value=\"JBuilder\"> JBuilder <br>" +
041 "<input type=\"checkbox\" name=\"tools\" value=\"Sun One Studio\"> Sun One Studio <br>" +
042 "<input type=\"checkbox\" name=\"tools\" value=\"iné\"> iné " +
043 "<input type=\"text\" name=\"other_tool\" class=\"form\" size=\"20\">" +
044 "</td></tr></table></fieldset><br>" +
045 "<em>Polia označené * sú povinné!</em>" +
046 "<div align=\"right\">" +
047 "<input type=\"submit\" name=\"odoslat\" class=\"submit\" value=\"Odoslať\"></div>" +
048 "</form></td></tr></table>" +
049 "</body></html>");
050 out.close();
051 }
052
053 public void doPost(HttpServletRequest req, HttpServletResponse res)
054 throws ServletException, IOException {
055
056 res.setContentType("text/html;charset=windows-1250");
057 PrintWriter out = res.getWriter();
058
059 // získanie obsahu parametra "name"
060 String name = req.getParameter("name");
061 name = new String(name.getBytes("ISO-8859-1"), "windows-1250");
062 if(name.equals("")) {
063 name = "<font color=\"#FF0000\">Zadajte prosím meno!</font>";
064 }
065
066 // získanie obsahu parametra "surname"
067 String surname = req.getParameter("surname");
068 surname = new String(surname.getBytes("ISO-8859-1"), "windows-1250");
069
070 // získanie obsahu parametra "email"
071 String email = req.getParameter("email");
072 if( email.equals("") | email.indexOf("@") == -1) {
073 email = "<font color=\"#FF0000\">Zadajte prosím váš email!</font>";
074 }
075
076 // získanie obsahu parametra "job"
077 String job = req.getParameter("job");
078 job = new String(job.getBytes("ISO-8859-1"), "windows-1250");
079 if(job.equals("")) {
080 job = "<font color=\"#FF0000\">Nezadali ste vaše pracovné zaradenie!</font>";
081 }
082
083 // získanie obsahu parametra "tools"
084 String[] tools = req.getParameterValues("tools");
085
086 // získanie obsahu parametra "other_tool"
087 String other_tool = req.getParameter("other_tool");
088 other_tool = new String(other_tool.getBytes("ISO-8859-1"), "windows-1250");
089
090 // vypísanie získaných a otestovaných parametrov
091 out.print("<html><head><title>Výsledky ...</title></head><body>" +
092 "<b><u>Osobné údaje a zaradenie:</u></b><br>" +
093 "<b>Meno: </b>" + name + "<br>" +
094 "<b>Priezvisko: </b>" + surname + "<br>" +
095 "<b>Email: </b>" + email + "<br>" +
096 "<b>Zaradenie: </b>" + job + "<br><p>" +
097 "<b><u>Používané nástroje:</u></b><br>");
098
099 // vypísanie používaných nástrojov
100 if ( tools != null) {
101 for (int i = 0; i < tools.length; i++) {
102 if (tools[i].equals("iné")) {
103 out.print("- " + tools[i] + ": " + other_tool +"<br>");
104 } else {
105 out.print("- " + tools[i] + "<br>");
106 }
107 }
108 }
109
110 out.print("<p>Ďakujeme za všetky poskytnuté údaje.</p>" +
111 "<hr><a href=\"" +
req.getRequestURI() +
112 "\">Anketa</a></body></html>");
113 out.close();
114 }
115 }
|