Java Code Examples for javax.servlet.jsp.PageContext#getResponse()

The following examples show how to use javax.servlet.jsp.PageContext#getResponse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ListTagUtil.java    From uyuni with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Includes arbitrary _local_ url as content
 * @param ctx caller's page context
 * @param url local url
 * @throws JspException if something goes wrong
 *
 * Note: Local means Urls in the same application
 */
public static void includeContent(PageContext ctx, String url) throws JspException {
    HttpServletRequest request = (HttpServletRequest) ctx.getRequest();
    HttpServletResponse response = (HttpServletResponse) ctx.getResponse();
    RequestDispatcher rd =
        request.getSession(true).getServletContext().getRequestDispatcher(url);
    if (rd == null) {
        ListTagUtil.write(ctx, "<!-- " + url + " not found -->");
    }
    else {
        try {
            BufferedResponseWrapper wrapper = new BufferedResponseWrapper(response);
            rd.include(request, wrapper);
            wrapper.flush();
            ListTagUtil.write(ctx, wrapper.getBufferedOutput());
        }
        catch (Exception e) {
            throw new JspException(e);
        }
    }
}
 
Example 2
Source File: TagUtils.java    From sinavi-jfw with Apache License 2.0 6 votes vote down vote up
/**
 * リンクとして出力するURLを生成します。
 * @param url パス
 * @param params パスに付与するパラメータ
 * @param pageContext ページコンテキスト
 * @param isHtmlEscape HTMLの特殊文字をエスケープするかどうか
 * @param isJavaScriptEscape JavaScriptの特殊文字をエスケープするかどうか
 * @return パス
 * @throws JspException 予期しない例外
 */
public static String createUrl(String url, Map<String, String[]> params, PageContext pageContext, boolean isHtmlEscape, boolean isJavaScriptEscape) throws JspException {
    HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
    HttpServletResponse response = (HttpServletResponse)pageContext.getResponse();

    StringBuilder buffer = new StringBuilder();
    UrlType urlType = getUrlType(url);
    if (urlType == UrlType.CONTEXT_RELATIVE) {
        buffer.append(request.getContextPath());
        if (!url.startsWith("/")) {
            buffer.append("/");
        }
    }
    buffer.append(replaceUriTemplateParams(url, params, pageContext));
    buffer.append(createQueryString(params, (url.indexOf("?") == -1), pageContext));

    String urlStr = buffer.toString();
    if (urlType != UrlType.ABSOLUTE) {
        urlStr = response.encodeURL(urlStr);
    }

    urlStr = isHtmlEscape ? HtmlUtils.htmlEscape(urlStr) : urlStr;
    urlStr = isJavaScriptEscape ? JavaScriptUtils.javaScriptEscape(urlStr) : urlStr;

    return urlStr;
}
 
Example 3
Source File: ListTagUtil.java    From spacewalk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Includes arbitrary _local_ url as content
 * @param ctx caller's page context
 * @param url local url
 * @throws JspException if something goes wrong
 *
 * Note: Local means Urls in the same application
 */
public static void includeContent(PageContext ctx, String url) throws JspException {
    HttpServletRequest request = (HttpServletRequest) ctx.getRequest();
    HttpServletResponse response = (HttpServletResponse) ctx.getResponse();
    RequestDispatcher rd =
        request.getSession(true).getServletContext().getRequestDispatcher(url);
    if (rd == null) {
        ListTagUtil.write(ctx, "<!-- " + url + " not found -->");
    }
    else {
        try {
            BufferedResponseWrapper wrapper = new BufferedResponseWrapper(response);
            rd.include(request, wrapper);
            wrapper.flush();
            ListTagUtil.write(ctx, wrapper.getBufferedOutput());
        }
        catch (Exception e) {
            throw new JspException(e);
        }
    }
}
 
Example 4
Source File: WebBean.java    From Openfire with Apache License 2.0 5 votes vote down vote up
public void init(PageContext pageContext){
    this.request = (HttpServletRequest)pageContext.getRequest();
    this.response = (HttpServletResponse)pageContext.getResponse();
    this.session = pageContext.getSession();
    this.application = pageContext.getServletContext();
    this.out = pageContext.getOut();
}
 
Example 5
Source File: JspToolContext.java    From velocity-tools with Apache License 2.0 5 votes vote down vote up
public JspToolContext(VelocityEngine velocity,
                      PageContext pageContext)
{
    super(velocity,
          (HttpServletRequest)pageContext.getRequest(),
          (HttpServletResponse)pageContext.getResponse(),
          pageContext.getServletContext());

    this.pageContext = pageContext;
}
 
Example 6
Source File: PankuzuTag.java    From sinavi-jfw with Apache License 2.0 4 votes vote down vote up
String encodeURL(String url) {
    PageContext pageContext = (PageContext) getJspContext();
    HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
    return response.encodeURL(url);
}
 
Example 7
Source File: JspAwareRequestContext.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Create a new JspAwareRequestContext for the given page context,
 * using the given model attributes for Errors retrieval.
 * @param pageContext current JSP page context
 * @param model the model attributes for the current view
 * (can be {@code null}, using the request attributes for Errors retrieval)
 */
public JspAwareRequestContext(PageContext pageContext, @Nullable Map<String, Object> model) {
	super((HttpServletRequest) pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse(),
			pageContext.getServletContext(), model);
	this.pageContext = pageContext;
}
 
Example 8
Source File: JspAwareRequestContext.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Create a new JspAwareRequestContext for the given page context,
 * using the given model attributes for Errors retrieval.
 * @param pageContext current JSP page context
 * @param model the model attributes for the current view
 * (can be {@code null}, using the request attributes for Errors retrieval)
 */
public JspAwareRequestContext(PageContext pageContext, @Nullable Map<String, Object> model) {
	super((HttpServletRequest) pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse(),
			pageContext.getServletContext(), model);
	this.pageContext = pageContext;
}