1 22 package org.jboss.ejb3.test.dd.web.servlets; 23 24 import java.io.IOException ; 25 import java.io.PrintWriter ; 26 import java.security.Principal ; 27 import javax.servlet.RequestDispatcher ; 28 import javax.servlet.ServletConfig ; 29 import javax.servlet.ServletException ; 30 import javax.servlet.http.HttpServlet ; 31 import javax.servlet.http.HttpServletRequest ; 32 import javax.servlet.http.HttpServletResponse ; 33 34 39 public class IncludeServlet extends HttpServlet 40 { 41 protected void processRequest(HttpServletRequest request, HttpServletResponse response) 42 throws ServletException , IOException 43 { 44 Principal user = request.getUserPrincipal(); 45 boolean isSecure = request.getRemoteUser() != null; 46 response.setBufferSize(2048); 47 PrintWriter out = response.getWriter(); 48 response.setContentType("text/html"); 49 out.println("<html>"); 50 out.println("<head><title>IncludeServlet</title></head>"); 51 out.println("<h1>IncludeServlet Accessed</h1>"); 52 out.println("<body>You have accessed this servlet as user:"+user); 53 try 54 { 55 out.println("Accessing /restricted/SecureEJBAccess?includeHead=false<br>"); 56 RequestDispatcher rd = request.getRequestDispatcher("/restricted/SecureEJBAccess?includeHead=false"); 57 rd.include(request, response); 58 } 59 catch(ServletException e) 60 { 61 if( isSecure == true ) 62 throw e; 63 out.println("Access to /restricted/SecureEJBAccess failed as expected<br>"); 64 } 65 66 out.println("Accessing /UnsecureEJBAccess?includeHead=false<br>"); 67 RequestDispatcher rd = request.getRequestDispatcher("/UnsecureEJBAccess?includeHead=false"); 68 rd.include(request, response); 69 out.println("</body></html>"); 70 out.close(); 71 } 72 73 protected void doGet(HttpServletRequest request, HttpServletResponse response) 74 throws ServletException , IOException 75 { 76 processRequest(request, response); 77 } 78 79 protected void doPost(HttpServletRequest request, HttpServletResponse response) 80 throws ServletException , IOException 81 { 82 processRequest(request, response); 83 } 84 85 } 86 | Popular Tags |