1 package servletunit; 2 3 19 import javax.servlet.*; 20 import java.io.IOException ; 21 22 25 public class RequestDispatcherSimulator implements RequestDispatcher 26 { 27 private Object dispatchedResource; 28 37 public RequestDispatcherSimulator( Object dispatchedResource ) 38 { 39 this.dispatchedResource = dispatchedResource; 40 } 41 44 public void forward( ServletRequest request, ServletResponse response ) throws ServletException, IOException 45 { 46 if( dispatchedResource instanceof Servlet ) 47 ((Servlet)dispatchedResource).service( request, response ); 48 } 49 public void include( ServletRequest request, ServletResponse response ) throws ServletException, IOException 50 { 51 System.out.println( dispatchedResource.toString() ); 52 } 53 54 public String getForward() { 55 if (dispatchedResource instanceof String ) 56 return (String ) dispatchedResource; 57 else 58 return dispatchedResource.getClass().toString(); 59 } 60 } 61 | Popular Tags |