001: /* HttpServlet.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: Mon Dec 22 18:48:22 2003, Created by tomyeh
010: }}IS_NOTE
011:
012: Copyright (C) 2003 Potix Corporation. All Rights Reserved.
013:
014: {{IS_RIGHT
015: This program is distributed under GPL Version 2.0 in the hope that
016: it will be useful, but WITHOUT ANY WARRANTY.
017: }}IS_RIGHT
018: */
019: package org.zkoss.web.servlet.http;
020:
021: import java.util.Map;
022:
023: import javax.servlet.ServletContext;
024: import javax.servlet.ServletRequest;
025: import javax.servlet.ServletResponse;
026: import javax.servlet.ServletException;
027: import javax.servlet.http.HttpServletRequest;
028: import javax.servlet.http.HttpServletResponse;
029:
030: import org.zkoss.web.servlet.Servlets;
031:
032: /**
033: * Extended javax.servlet.http.HttpServlet to provide extra utilities.
034: *
035: * @author tomyeh
036: */
037: public class HttpServlet extends javax.servlet.http.HttpServlet {
038: /**
039: * Redirects to another page. Note: it supports only HTTP.
040: *
041: * <p>It resolves "*" contained in URI, if any, to the proper Locale,
042: * and the browser code.
043: * Refer to {@link Servlets#locate(ServletContext, ServletRequest, String, Locator)}
044: * for details.
045: *
046: * @param page the page's uri; null to denote the same request
047: * @param mode one of {@link Servlets#OVERWRITE_URI}, {@link Servlets#IGNORE_PARAM},
048: * and {@link Servlets#APPEND_PARAM}. It defines how to handle if both uri
049: * and params contains the same parameter.
050: * mode is used only if both uri contains query string and params is
051: * not empty.
052: */
053: protected void sendRedirect(HttpServletRequest request,
054: HttpServletResponse response, String page, Map params,
055: int mode) throws ServletException, java.io.IOException {
056: if (page != null)
057: page = Servlets.locate(getServletContext(), request, page,
058: null);
059: Https.sendRedirect(getServletContext(), request, response,
060: page, params, mode);
061: }
062:
063: /** Forward to the specified page.
064: *
065: * <p>It resolves "*" contained in URI, if any, to the proper Locale,
066: * and the browser code.
067: * Refer to {@link Servlets#locate(ServletContext, ServletRequest, String, Locator)}
068: * for details.
069: */
070: protected final void forward(ServletContext ctx,
071: ServletRequest request, ServletResponse response, String uri)
072: throws ServletException, java.io.IOException {
073: forward(ctx, request, response, uri, null, 0);
074: }
075:
076: /** Forward to the specified page with parameters.
077: *
078: * <p>It resolves "*" contained in URI, if any, to the proper Locale,
079: * and the browser code.
080: * Refer to {@link Servlets#locate(ServletContext, ServletRequest, String, Locator)}
081: * for details.
082: */
083: protected final void forward(ServletContext ctx,
084: ServletRequest request, ServletResponse response,
085: String uri, Map params, int mode) throws ServletException,
086: java.io.IOException {
087: if (uri != null)
088: uri = Servlets.locate(getServletContext(), request, uri,
089: null);
090: Https.forward(ctx, request, response, uri, params, mode);
091: }
092:
093: /** Includes the specified page.
094: *
095: * <p>It resolves "*" contained in URI, if any, to the proper Locale,
096: * and the browser code.
097: * Refer to {@link Servlets#locate(ServletContext, ServletRequest, String, Locator)}
098: * for details.
099: */
100: protected final void include(ServletContext ctx,
101: ServletRequest request, ServletResponse response, String uri)
102: throws ServletException, java.io.IOException {
103: include(ctx, request, response, uri, null, 0);
104: }
105:
106: /** Includes the specified page with parameters.
107: *
108: * <p>It resolves "*" contained in URI, if any, to the proper Locale,
109: * and the browser code.
110: * Refer to {@link Servlets#locate(ServletContext, ServletRequest, String, Locator)}
111: * for details.
112: */
113: protected final void include(ServletContext ctx,
114: ServletRequest request, ServletResponse response,
115: String uri, Map params, int mode) throws ServletException,
116: java.io.IOException {
117: if (uri != null)
118: uri = Servlets.locate(getServletContext(), request, uri,
119: null);
120: Https.include(ctx, request, response, uri, params, mode);
121: }
122: }
|