1. 程式人生 > >servlet/jsp隨記

servlet/jsp隨記

sent pos 響應 OS destroy () proc exc leg

Servlet接口

技術分享圖片
public interface Servlet {
    ......

    public void init(ServletConfig config) throws ServletException;

    public ServletConfig getServletConfig();

    public void service(ServletRequest req, ServletResponse res)
            throws ServletException, IOException;

    public String getServletInfo();

    
public void destroy(); ...... }
View Code

RequestDispatcher接口

技術分享圖片
public interface RequestDispatcher {

    ......

   /**
     * Forwards a request from
     * a servlet to another resource (servlet, JSP file, or
     * HTML file) on the server. This method allows
     * one servlet to do preliminary processing of
     * a request and another resource to generate
     * the response.
     *
     * <p>For a <code>RequestDispatcher</code> obtained via 
     * <code>getRequestDispatcher()</code>, the <code>ServletRequest</code> 
     * object has its path elements and parameters adjusted to match
     * the path of the target resource.
     *
     * <p><code>forward</code> should be called before the response has been 
     * committed to the client (before response body output has been flushed). 
     * If the response already has been committed, this method throws
     * an <code>IllegalStateException</code>.
     * Uncommitted output in the response buffer is automatically cleared 
     * before the forward.
     *
     * <p>The request and response parameters must be either the same
     * objects as were passed to the calling servlet‘s service method or be
     * subclasses of the {
@link ServletRequestWrapper} or * {@link ServletResponseWrapper} classes * that wrap them. * * <p>This method sets the dispatcher type of the given request to * <code>DispatcherType.FORWARD</code>. * * @param request a {@link ServletRequest} object that represents the * request the client makes of the servlet * *
@param response a {@link ServletResponse} object that represents * the response the servlet returns to the client * * @throws ServletException if the target resource throws this exception * * @throws IOException if the target resource throws this exception * * @throws IllegalStateException if the response was already committed * * @see ServletRequest#getDispatcherType */ public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException; /** * * Includes the content of a resource (servlet, JSP page, * HTML file) in the response. In essence, this method enables * programmatic server-side includes. * * <p>The {@link ServletResponse} object has its path elements * and parameters remain unchanged from the caller‘s. The included * servlet cannot change the response status code or set headers; * any attempt to make a change is ignored. * * <p>The request and response parameters must be either the same * objects as were passed to the calling servlet‘s service method or be * subclasses of the {@link ServletRequestWrapper} or * {@link ServletResponseWrapper} classes that wrap them. * * <p>This method sets the dispatcher type of the given request to * <code>DispatcherType.INCLUDE</code>. * * @param request a {@link ServletRequest} object that contains the * client‘s request * * @param response a {@link ServletResponse} object that contains the * servlet‘s response * * @throws ServletException if the included resource throws this * exception * * @throws IOException if the included resource throws this exception * * @see ServletRequest#getDispatcherType */ public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException; ...... }
View Code

JSP內置的對象

技術分享圖片
- request:封裝客戶端的請求,其中包含來自GET或POST請求的參數; 
- response:封裝服務器對客戶端的響應; 
- pageContext:通過該對象可以獲取其他對象; 
- session:封裝用戶會話的對象; 
- application:封裝服務器運行環境的對象; 
- out:輸出服務器響應的輸出流對象; 
- config:Web應用的配置對象; 
- page:JSP頁面本身(相當於Java程序中的this); 
- exception:封裝頁面拋出異常的對象
View Code

servlet/jsp隨記