List of usage examples for javax.servlet.jsp PageContext include
abstract public void include(String relativeUrlPath) throws ServletException, IOException;
Causes the resource specified to be processed as part of the current ServletRequest and ServletResponse being processed by the calling Thread.
From source file:cn.org.pomer.web.DirectResult.java
private void doDispatcher(HttpServletResponse response, HttpServletRequest request, String resultCodeAsLocation) throws IOException, ServletException { if (_log.isInfoEnabled()) { _log.info("Forwarding to location:" + resultCodeAsLocation); }/* ww w .j a v a 2 s . co m*/ PageContext pageContext = ServletActionContext.getPageContext(); if (pageContext != null) { pageContext.include(resultCodeAsLocation); return; } RequestDispatcher dispatcher = request.getRequestDispatcher(resultCodeAsLocation); if (dispatcher == null) { response.sendError(404, "result '" + resultCodeAsLocation + "' not found"); return; } if (!response.isCommitted() && (request.getAttribute("javax.servlet.include.servlet_path") == null)) { request.setAttribute("struts.view_uri", resultCodeAsLocation); request.setAttribute("struts.request_uri", request.getRequestURI()); dispatcher.forward(request, response); } else { dispatcher.include(request, response); } }
From source file:de.hybris.platform.addonsupport.renderer.impl.DefaultAddOnCMSComponentRenderer.java
@Override public void renderComponent(final PageContext pageContext, final C component) throws ServletException, IOException { final Map<String, Object> exposedVariables = exposeVariables(pageContext, component); pageContext.include(getView(component)); unExposeVariables(pageContext, component, exposedVariables); }
From source file:com.jeeframework.webframework.filter.dispatcher.JSONJspServletDispatcherResult.java
/** * Dispatches to the given location. Does its forward via a * RequestDispatcher. If the dispatch fails a 404 error will be sent back in * the http response.//from w w w .j a va 2 s . c o m * * @param finalLocation * the location to dispatch to. * @param invocation * the execution state of the action * @throws Exception * if an error occurs. If the dispatch fails the error will go * back via the HTTP request. */ public void doExecute(String finalLocation, ActionInvocation invocation) throws Exception { if (log.isDebugEnabled()) { log.debug("Forwarding to location " + finalLocation); } PageContext pageContext = ServletActionContext.getPageContext(); if (pageContext != null) { pageContext.include(finalLocation); } else { HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); String curFileName = StringUtils.getFileNamePreffix(finalLocation); String curFileSuffix = StringUtils.getFilenameExtension(finalLocation); String dstFile = curFileName; if (curFileName.startsWith(JSONJspServletDispatcherResult.JSONJSP_PREFIX) && curFileName.length() > JSONJspServletDispatcherResult.JSONJSP_PREFIX.length()) { dstFile = curFileName.substring(JSONJspServletDispatcherResult.JSONJSP_PREFIX.length()); } if (curFileName.endsWith(JSONJspServletDispatcherResult.JSONJSP_SUFFIX) && curFileName.length() > JSONJspServletDispatcherResult.JSONJSP_SUFFIX.length()) { dstFile = dstFile.substring(0, dstFile.length() - JSONJspServletDispatcherResult.JSONJSP_SUFFIX.length()); } String webroot = System.getProperty(StrutsPrepareAndExecuteFilterWrapper.CUR_DEFAULT_WEBROOT_KEY); if (!webroot.endsWith("/") && !webroot.endsWith("\\")) { webroot = webroot + "/"; } String dstFilePath = webroot + finalLocation; File dstCurjsp = new File(dstFilePath); // && !dstCurjsp.exists() if (!dstCurjsp.exists()) { try { String srcFilePath = webroot;// if (!(dstFile.startsWith("/") || dstFile.startsWith("\\"))) { srcFilePath = srcFilePath + "/"; } srcFilePath = srcFilePath + dstFile + "." + curFileSuffix; File srcCurjsp = new File(srcFilePath); String srcCurjspContent = FileUtils.readFileToString(srcCurjsp, StrutsPrepareAndExecuteFilterWrapper.FILE_ENCODING); srcCurjspContent = srcCurjspContent.replaceAll("[\r\n\t]", ""); FileUtils.writeStringToFile(dstCurjsp, srcCurjspContent, StrutsPrepareAndExecuteFilterWrapper.FILE_ENCODING); } catch (IOException e) { e.printStackTrace(); System.out.println("? jsonjsp " + dstFilePath + "error"); } } RequestDispatcher dispatcher = request.getRequestDispatcher(finalLocation); // if the view doesn't exist, let's do a 404 if (dispatcher == null) { response.sendError(404, "result '" + finalLocation + "' not found"); return; } // If we're included, then include the view // Otherwise do forward // This allow the page to, for example, set content type if (!response.isCommitted() && (request.getAttribute("javax.servlet.include.servlet_path") == null)) { request.setAttribute("struts.view_uri", finalLocation); request.setAttribute("struts.request_uri", request.getRequestURI()); dispatcher.forward(request, response); } else { dispatcher.include(request, response); } } }
From source file:org.apache.jsp.html.portlet.journal.edit_005farticle_jsp.java
private void _format(long groupId, Element contentParentElement, Element xsdParentElement, IntegerWrapper count, Integer depth, boolean repeatablePrototype, PageContext pageContext, HttpServletRequest request) throws Exception { depth = new Integer(depth.intValue() + 1); String languageId = LanguageUtil.getLanguageId(request); List<Element> xsdElements = xsdParentElement.elements(); for (Element xsdElement : xsdElements) { String nodeName = xsdElement.getName(); if (nodeName.equals("meta-data") || nodeName.equals("entry")) { continue; }/*from ww w . ja va 2s. co m*/ String elName = xsdElement.attributeValue("name", StringPool.BLANK); String elType = xsdElement.attributeValue("type", StringPool.BLANK); String elIndexType = xsdElement.attributeValue("index-type", StringPool.BLANK); String repeatable = xsdElement.attributeValue("repeatable"); boolean elRepeatable = GetterUtil.getBoolean(repeatable); String elParentStructureId = xsdElement.attributeValue("parent-structure-id"); Map<String, String> elMetaData = _getMetaData(xsdElement, elName); List<Element> elSiblings = null; List<Element> contentElements = contentParentElement.elements(); for (Element contentElement : contentElements) { if (elName.equals(contentElement.attributeValue("name", StringPool.BLANK))) { elSiblings = _getSiblings(contentParentElement, elName); break; } } if (elSiblings == null) { elSiblings = new ArrayList<Element>(); Element contentElement = SAXReaderUtil.createElement("dynamic-element"); contentElement.addAttribute("instance-id", PwdGenerator.getPassword()); contentElement.addAttribute("name", elName); contentElement.addAttribute("type", elType); contentElement.addAttribute("index-type", elIndexType); contentElement.add(SAXReaderUtil.createElement("dynamic-content")); elSiblings.add(contentElement); } for (int siblingIndex = 0; siblingIndex < elSiblings.size(); siblingIndex++) { Element contentElement = elSiblings.get(siblingIndex); String elInstanceId = contentElement.attributeValue("instance-id"); String elContent = GetterUtil.getString(contentElement.elementText("dynamic-content")); if (!elType.equals("document_library") && !elType.equals("image_gallery") && !elType.equals("text") && !elType.equals("text_area") && !elType.equals("text_box")) { elContent = HtmlUtil.toInputSafe(elContent); } String elLanguageId = StringPool.BLANK; Element dynamicContentEl = contentElement.element("dynamic-content"); if (dynamicContentEl != null) { elLanguageId = dynamicContentEl.attributeValue("language-id", StringPool.BLANK); } else { elLanguageId = languageId; } if (repeatablePrototype) { repeatablePrototype = (siblingIndex == 0); } request.setAttribute(WebKeys.JOURNAL_ARTICLE_GROUP_ID, String.valueOf(groupId)); request.setAttribute(WebKeys.JOURNAL_ARTICLE_CONTENT_EL, contentElement); request.setAttribute(WebKeys.JOURNAL_STRUCTURE_EL, xsdElement); request.setAttribute(WebKeys.JOURNAL_STRUCTURE_EL_CONTENT, elContent); request.setAttribute(WebKeys.JOURNAL_STRUCTURE_EL_COUNT, count); request.setAttribute(WebKeys.JOURNAL_STRUCTURE_EL_DEPTH, depth); request.setAttribute(WebKeys.JOURNAL_STRUCTURE_EL_INSTANCE_ID, elInstanceId); request.setAttribute(WebKeys.JOURNAL_STRUCTURE_EL_LANGUAGE_ID, elLanguageId); request.setAttribute(WebKeys.JOURNAL_STRUCTURE_EL_META_DATA, elMetaData); request.setAttribute(WebKeys.JOURNAL_STRUCTURE_EL_NAME, elName); request.setAttribute(WebKeys.JOURNAL_STRUCTURE_EL_PARENT_ID, elParentStructureId); request.setAttribute(WebKeys.JOURNAL_STRUCTURE_EL_REPEATABLE, String.valueOf(elRepeatable)); request.setAttribute(WebKeys.JOURNAL_STRUCTURE_EL_REPEATABLE_PROTOTYPE, String.valueOf(repeatablePrototype)); request.setAttribute(WebKeys.JOURNAL_STRUCTURE_EL_TYPE, elType); request.setAttribute(WebKeys.JOURNAL_STRUCTURE_EL_INDEX_TYPE, elIndexType); pageContext.include("/html/portlet/journal/edit_article_content_xsd_el.jsp"); count.increment(); if (!elType.equals("list") && !elType.equals("multi-list") && !contentElement.elements().isEmpty()) { pageContext.include("/html/portlet/journal/edit_article_content_xsd_el_top.jsp"); _format(groupId, contentElement, xsdElement, count, depth, repeatablePrototype, pageContext, request); request.setAttribute(WebKeys.JOURNAL_STRUCTURE_CLOSE_DROPPABLE_TAG, Boolean.TRUE.toString()); pageContext.include("/html/portlet/journal/edit_article_content_xsd_el_bottom.jsp"); } request.setAttribute(WebKeys.JOURNAL_STRUCTURE_CLOSE_DROPPABLE_TAG, Boolean.FALSE.toString()); pageContext.include("/html/portlet/journal/edit_article_content_xsd_el_bottom.jsp"); } } }
From source file:org.apache.jsp.html.portlet.journal.edit_005fstructure_jsp.java
private void _format(Element root, IntegerWrapper count, Integer depth, IntegerWrapper tabIndex, PageContext pageContext, HttpServletRequest request) throws Exception { depth = new Integer(depth.intValue() + 1); List children = root.elements(); Boolean hasSiblings = null; if (children.size() > 1) { hasSiblings = Boolean.TRUE; } else {/* w ww. j a v a2 s. c om*/ hasSiblings = Boolean.FALSE; } Iterator itr = children.iterator(); while (itr.hasNext()) { Element el = (Element) itr.next(); if (el.getName().equals("meta-data")) { continue; } request.setAttribute(WebKeys.JOURNAL_STRUCTURE_EL, el); request.setAttribute(WebKeys.JOURNAL_STRUCTURE_EL_COUNT, count); request.setAttribute(WebKeys.JOURNAL_STRUCTURE_EL_DEPTH, depth); request.setAttribute(WebKeys.JOURNAL_STRUCTURE_EL_SIBLINGS, hasSiblings); request.setAttribute(WebKeys.TAB_INDEX, tabIndex); pageContext.include("/html/portlet/journal/edit_structure_xsd_el.jsp"); count.increment(); _format(el, count, depth, tabIndex, pageContext, request); } }
From source file:org.apache.struts.tiles.TilesUtilImpl.java
/** * Do an include using PageContext.include(). * * This method is used by the Tiles package when an include is required. * The Tiles package can use indifferently any form of this method. * @param uri Uri or Definition name to forward. * @param pageContext Current page context. * @param flush If the writer should be flushed before the include *//*from w w w . j a v a2s . co m*/ public void doInclude(String uri, PageContext pageContext, boolean flush) throws IOException, ServletException { try { // perform include with new JSP 2.0 method that supports flushing if (include != null) { include.invoke(pageContext, new Object[] { uri, Boolean.valueOf(flush) }); return; } } catch (IllegalAccessException e) { log.debug("Could not find JSP 2.0 include method. Using old one.", e); } catch (InvocationTargetException e) { if (e.getCause() instanceof ServletException) { throw ((ServletException) e.getCause()); } else if (e.getCause() instanceof IOException) { throw ((IOException) e.getCause()); } else { throw new ServletException(e); } } pageContext.include(uri); }
From source file:org.apache.struts2.dispatcher.ServletDispatcherResult.java
/** * Dispatches to the given location. Does its forward via a RequestDispatcher. If the * dispatch fails a 404 error will be sent back in the http response. * * @param finalLocation the location to dispatch to. * @param invocation the execution state of the action * @throws Exception if an error occurs. If the dispatch fails the error will go back via the * HTTP request.//w w w . j av a 2 s. c o m */ public void doExecute(String finalLocation, ActionInvocation invocation) throws Exception { if (LOG.isDebugEnabled()) { LOG.debug("Forwarding to location " + finalLocation); } PageContext pageContext = ServletActionContext.getPageContext(); if (pageContext != null) { pageContext.include(finalLocation); } else { HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); RequestDispatcher dispatcher = request.getRequestDispatcher(finalLocation); //add parameters passed on the location to #parameters // see WW-2120 if (StringUtils.isNotEmpty(finalLocation) && finalLocation.indexOf("?") > 0) { String queryString = finalLocation.substring(finalLocation.indexOf("?") + 1); Map<String, Object> parameters = getParameters(invocation); Map<String, Object> queryParams = urlHelper.parseQueryString(queryString, true); if (queryParams != null && !queryParams.isEmpty()) parameters.putAll(queryParams); } // if the view doesn't exist, let's do a 404 if (dispatcher == null) { response.sendError(404, "result '" + finalLocation + "' not found"); return; } //if we are inside an action tag, we always need to do an include Boolean insideActionTag = (Boolean) ObjectUtils .defaultIfNull(request.getAttribute(StrutsStatics.STRUTS_ACTION_TAG_INVOCATION), Boolean.FALSE); // If we're included, then include the view // Otherwise do forward // This allow the page to, for example, set content type if (!insideActionTag && !response.isCommitted() && (request.getAttribute("javax.servlet.include.servlet_path") == null)) { request.setAttribute("struts.view_uri", finalLocation); request.setAttribute("struts.request_uri", request.getRequestURI()); dispatcher.forward(request, response); } else { dispatcher.include(request, response); } } }
From source file:org.apache.struts2.result.ServletDispatcherResult.java
/** * Dispatches to the given location. Does its forward via a RequestDispatcher. If the * dispatch fails a 404 error will be sent back in the http response. * * @param finalLocation the location to dispatch to. * @param invocation the execution state of the action * @throws Exception if an error occurs. If the dispatch fails the error will go back via the * HTTP request.// w w w. ja v a 2 s. co m */ public void doExecute(String finalLocation, ActionInvocation invocation) throws Exception { LOG.debug("Forwarding to location: {}", finalLocation); PageContext pageContext = ServletActionContext.getPageContext(); if (pageContext != null) { pageContext.include(finalLocation); } else { HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); RequestDispatcher dispatcher = request.getRequestDispatcher(finalLocation); //add parameters passed on the location to #parameters // see WW-2120 if (StringUtils.isNotEmpty(finalLocation) && finalLocation.indexOf("?") > 0) { String queryString = finalLocation.substring(finalLocation.indexOf("?") + 1); HttpParameters parameters = getParameters(invocation); Map<String, Object> queryParams = urlHelper.parseQueryString(queryString, true); if (queryParams != null && !queryParams.isEmpty()) { parameters = HttpParameters.create(queryParams).withParent(parameters).build(); invocation.getInvocationContext().setParameters(parameters); // put to extraContext, see Dispatcher#createContextMap invocation.getInvocationContext().getContextMap().put("parameters", parameters); } } // if the view doesn't exist, let's do a 404 if (dispatcher == null) { LOG.warn("Location {} not found!", finalLocation); response.sendError(404, "result '" + finalLocation + "' not found"); return; } //if we are inside an action tag, we always need to do an include Boolean insideActionTag = (Boolean) ObjectUtils .defaultIfNull(request.getAttribute(StrutsStatics.STRUTS_ACTION_TAG_INVOCATION), Boolean.FALSE); // If we're included, then include the view // Otherwise do forward // This allow the page to, for example, set content type if (!insideActionTag && !response.isCommitted() && (request.getAttribute("javax.servlet.include.servlet_path") == null)) { request.setAttribute("struts.view_uri", finalLocation); request.setAttribute("struts.request_uri", request.getRequestURI()); dispatcher.forward(request, response); } else { dispatcher.include(request, response); } } }