servlet/jsp随记
Posted suheng
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了servlet/jsp随记相关的知识,希望对你有一定的参考价值。
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(); ...... }
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; ...... }
JSP内置的对象
- request:封装客户端的请求,其中包含来自GET或POST请求的参数; - response:封装服务器对客户端的响应; - pageContext:通过该对象可以获取其他对象; - session:封装用户会话的对象; - application:封装服务器运行环境的对象; - out:输出服务器响应的输出流对象; - config:Web应用的配置对象; - page:JSP页面本身(相当于Java程序中的this); - exception:封装页面抛出异常的对象
以上是关于servlet/jsp随记的主要内容,如果未能解决你的问题,请参考以下文章