Электронный магазин на Java и XML

         

Пример сервлета для просмотра результатов отчета - часть 2


Листинг 7.32. Метод doGet класса QanalysisServ (QanalysisServ.java)

// entry with password public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("Qanalysis doGet"); resp.setContentType("text/html"); PrintWriter out = new PrintWriter(resp.getOutputStream()); String user = req.getParameter("username"); String tmp = req.getParameter("userpw"); // Obviously this could be a lot more complex if( !passwd.equals( tmp )){ errorMsg( out, "404 page not found", null ); return ; } if( qProp == null || qProp.size() == 0 ){ errorMsg( out, "Bad Initialization", null ); return ; } HttpSession session = req.getSession( true ); session.putValue( "username", user ); // Enumeration e = qProp.keys(); Vector v = new Vector(); while( e.hasMoreElements()){ String key = (String)e.nextElement(); // everything not "handler" or "analysis" is a XML file path name if( !( key.equals("handler") || key.equals("analysis"))){ v.addElement( key ); } } if( v.size() == 0 ){ errorMsg( out, "No Questionnaire files found", null ); return ; } out.println("<HTML>"); out.println("<HEAD><TITLE>QanalysisServ Output</TITLE> </HEAD>"); out.println("<BODY>"); out.println("<h2>Select The Questionnaire XML File</h2>"); out.println("Found " + v.size() + " XML files" + brcrlf ); out.println("<form method=\"POST\" action=\"http://localhost/servlet/Qanalysis\" >"); out.println("<select name=\"source\" >"); for( int i = 0 ; i < v.size() ; i++){ tmp = (String) v.elementAt( i ); out.println("<option value=\"" + tmp + "\" >" + tmp ); } out.println("</select>"); out.println("<input type=\"hidden\" name=\"username\" value=\"" + user + "\"><br>" ); out.println("<input type=\"hidden\" name=\"action\" value=\"select\" ><br>"); out.println("<input type=\"submit\" value=\"Start\" ><br>" ); out.println("</form>"); footer( out ); }




Содержание  Назад  Вперед