1 16 17 package org.apache.tester; 18 19 20 import java.io.*; 21 import javax.servlet.*; 22 import javax.servlet.http.*; 23 24 31 32 public class Session02 extends HttpServlet { 33 34 public void doGet(HttpServletRequest request, HttpServletResponse response) 35 throws IOException, ServletException { 36 37 response.setContentType("text/plain"); 38 PrintWriter writer = response.getWriter(); 39 40 boolean ok = true; 42 HttpSession session = request.getSession(false); 43 if (session == null) { 44 writer.println("Session02 FAILED - No existing session " + 45 request.getRequestedSessionId()); 46 ok = false; 47 } 48 49 if (ok) { 51 Object bean = session.getAttribute("sessionBean"); 52 if (bean == null) { 53 writer.println("Session02 FAILED - Cannot retrieve attribute"); 54 ok = false; 55 } else if (!(bean instanceof SessionBean)) { 56 writer.println("Session02 FAILED - Attribute instance of " + 57 bean.getClass().getName()); 58 ok = false; 59 } else { 60 String value = ((SessionBean) bean).getStringProperty(); 61 if (!"Session01".equals(value)) { 62 writer.println("Session02 FAILED - Property = " + value); 63 ok = false; 64 } 65 } 66 } 67 68 if (ok) 70 writer.println("Session02 PASSED"); 71 while (true) { 72 String message = StaticLogger.read(); 73 if (message == null) 74 break; 75 writer.println(message); 76 } 77 StaticLogger.reset(); 78 79 } 80 81 } 82 | Popular Tags |