List of usage examples for javax.servlet RequestDispatcher forward
public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException;
From source file:org.artifactory.webapp.servlet.RepoFilter.java
private void doRepoListing(HttpServletRequest request, HttpServletResponse response, String servletPath, ArtifactoryRequest artifactoryRequest) throws ServletException, IOException { log.debug("Forwarding internally to an apache-style listing page."); if (!servletPath.endsWith("/")) { response.sendRedirect(HttpUtils.getServletContextUrl(request) + servletPath + "/"); return;/* www . jav a2 s . c o m*/ } request.setAttribute(ATTR_ARTIFACTORY_REPOSITORY_PATH, artifactoryRequest.getRepoPath()); request.setAttribute(ATTR_ARTIFACTORY_REQUEST_PROPERTIES, artifactoryRequest.getProperties()); RequestDispatcher dispatcher = request.getRequestDispatcher("/ui/nativeBrowser"); dispatcher.forward(request, response); }
From source file:ejportal.webapp.filter.StaticFilter.java
/** * This method checks to see if the current path matches includes or * excludes. If it matches includes and not excludes, it forwards to the * static resource and ends the filter chain. Otherwise, it forwards to the * next filter in the chain.//from w w w .j av a 2s. com * * @param request * the current request * @param response * the current response * @param chain * the filter chain * @throws IOException * when something goes terribly wrong * @throws ServletException * when something goes wrong */ @Override public void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws IOException, ServletException { final UrlPathHelper urlPathHelper = new UrlPathHelper(); final String path = urlPathHelper.getPathWithinApplication(request); final boolean pathExcluded = PatternMatchUtils.simpleMatch(this.excludes, path); final boolean pathIncluded = PatternMatchUtils.simpleMatch(this.includes, path); if (pathIncluded && !pathExcluded) { if (this.logger.isDebugEnabled()) { this.logger.debug("Forwarding to static resource: " + path); } if (path.contains(".html")) { response.setContentType("text/html"); } final RequestDispatcher rd = this.getServletContext().getRequestDispatcher(path); rd.include(request, response); return; } if (this.servletName != null) { final RequestDispatcher rd = this.getServletContext().getNamedDispatcher(this.servletName); rd.forward(request, response); return; } chain.doFilter(request, response); }
From source file:at.gv.egiz.pdfas.web.helper.PdfAsHelper.java
public static void gotoError(ServletContext context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (PdfAsHelper.getFromDataUrl(request)) { response.sendRedirect(generateErrorURL(request, response)); } else {// w w w . j a v a2s . co m RequestDispatcher dispatcher = context.getRequestDispatcher(PDF_ERROR_PAGE); dispatcher.forward(request, response); } }
From source file:edu.ncsu.lib.browse.Browse.java
public void doGet(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws ServletException, IOException { if (!StringUtils.isNotBlank(httpRequest.getParameter("batchId")) && !StringUtils.isNotBlank(httpRequest.getParameter("callNumber"))) { throw new ServletException( "Invalid request: neither <batchId> or <callNumber> parameter were specified"); }/* w ww. j a va 2 s . c om*/ String matchType = "slice"; String classType = "LC"; String batchId = httpRequest.getParameter("batchId"); String callNumber = httpRequest.getParameter("callNumber"); // prevent html injection by stripping '<' and '>' if (callNumber != null) { callNumber = callNumber.replaceAll("<", "").replaceAll(">", ""); } try { if (!StringUtils.isNotEmpty(batchId)) { if (httpRequest.getParameter("classType") != null) { classType = httpRequest.getParameter("classType"); } String[] batchIdArray = retrieveBatchId(callNumber, classType); batchId = batchIdArray[0]; if (batchId == null) { log.error("CatKey or callNumber was not found in virtual browse index"); dispatchError(httpRequest, httpResponse); return; } matchType = batchIdArray[1]; httpRequest.getSession().setAttribute("virtualBrowseCallNumber", callNumber); } int numberBefore = 14; if (httpRequest.getParameter("before") != null) { numberBefore = Integer.parseInt(httpRequest.getParameter("before")); } int numberAfter = 15; if (httpRequest.getParameter("after") != null) { numberAfter = Integer.parseInt(httpRequest.getParameter("after")); } JSONObject result = getData(vsiUrl + "router.php?service=slice&batchId=" + batchId + "&numBefore=" + numberBefore + "&numAfter=" + numberAfter); log.info(vsiUrl + "router.php?service=slice&batchId=" + batchId + "&numBefore=" + numberBefore + "&numAfter=" + numberAfter); JSONArray results = result.getJSONArray("results"); //log.info("Got " + results.length() + " results"); ArrayList<String> requestKeys = new ArrayList<String>(); int start = 0; int end = results.length(); //adjust the start and end point to not include the current value if the numberBefore or the numberAfter is 0 if (numberBefore == 0) { start = 1; } if (numberAfter == 0) { end = results.length() - 1; } StringBuffer buf = new StringBuffer(); // int firstBatchId = 0; LinkedHashMap<Integer, String> currentCatkeys = new LinkedHashMap<Integer, String>(); HashMap<Integer, String> currentCallNums = new HashMap<Integer, String>(); for (int i = start; i < end; i++) { JSONObject item = results.getJSONObject(i); int currentBatchId = item.getInt("batchId"); currentCallNums.put(new Integer(currentBatchId), item.getString("minCallNum")); String catkey = "NCSU" + item.getString("catKey"); currentCatkeys.put(new Integer(currentBatchId), catkey); requestKeys.add(catkey); buf.append(catkey + ", "); } long startTime = System.currentTimeMillis(); log.info("Identified neighboring catkeys: " + buf.toString() + "finished in " + calculateTime(startTime)); browseData = new BrowseDataBean(Integer.parseInt(batchId)); //Map<String, Object> model = new HashMap<String, Object>(); //model.put("returnedBatchId", Integer.parseInt(batchId)); browseData.setMatchType(matchType); browseData.setCatKeys(currentCatkeys); browseData.setCallNums(currentCallNums); //model.put("matchType", matchType); //model.put("currentCatkeys", currentCatkeys); //model.put("currentCallNums", currentCallNums); String jsp; String displayType = httpRequest.getParameter("displayType"); if (displayType != null && displayType.equals("data")) { jsp = "browseData"; } else if (displayType != null && displayType.equals("popup")) { jsp = "browsePopup"; } else { //if(displayType.equals("full")){ if (callNumber == null) { if (httpRequest.getSession().getAttribute("virtualBrowseCallNumber") != null) { callNumber = httpRequest.getSession().getAttribute("virtualBrowseCallNumber").toString(); } if (callNumber == null) { callNumber = results.getJSONObject(numberBefore).getString("minCallNum"); } } jsp = "browse"; } browseData.setDisplayType(displayType); browseData.setLibrary("Your Library"); browseData.setLibraryShort("Library"); httpRequest.setAttribute("browseData", browseData); //model.put("displayType", displayType); //model.put("library", "Your library"); //model.put("libraryShort", "Library"); //log.info("TRLN processed request for " + buf.toString() + " in " + calculateTime(fullTime)); jsp = "jsp/" + jsp + ".jsp"; RequestDispatcher dispatcher = httpRequest.getRequestDispatcher(jsp); try { dispatcher.forward(httpRequest, httpResponse); } catch (Exception e) { dispatchError(httpRequest, httpResponse); } } catch (JSONException e) { log.error("Just threw a JSON exception."); e.printStackTrace(); dispatchError(httpRequest, httpResponse); } }
From source file:at.gv.egiz.pdfas.web.helper.PdfAsHelper.java
public static void gotoProvidePdf(ServletContext context, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (PdfAsHelper.getFromDataUrl(request)) { response.sendRedirect(generateProvideURL(request, response)); } else {/* w w w . ja va 2 s .c o m*/ RequestDispatcher dispatcher = context.getRequestDispatcher(PDF_PROVIDE_PAGE); dispatcher.forward(request, response); } }
From source file:com.xpn.xwiki.web.ActionFilter.java
/** * {@inheritDoc}/*from w w w . ja va2s.c o m*/ * * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain) */ @SuppressWarnings("unchecked") public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // Only HTTP requests can be dispatched. if (request instanceof HttpServletRequest && !Boolean.valueOf((String) request.getAttribute(ATTRIBUTE_ACTION_DISPATCHED))) { HttpServletRequest hrequest = (HttpServletRequest) request; Enumeration<String> parameterNames = hrequest.getParameterNames(); while (parameterNames.hasMoreElements()) { String parameter = parameterNames.nextElement(); if (parameter.startsWith(ACTION_PREFIX)) { String targetURL = getTargetURL(hrequest, parameter); RequestDispatcher dispatcher = hrequest.getRequestDispatcher(targetURL); if (dispatcher != null) { LOG.debug("Forwarding request to " + targetURL); request.setAttribute(ATTRIBUTE_ACTION_DISPATCHED, "true"); dispatcher.forward(hrequest, response); // Allow multiple calls to this filter as long as they are not nested. request.removeAttribute(ATTRIBUTE_ACTION_DISPATCHED); // If the request was forwarder to another path, don't continue the normal processing chain. return; } } } } // Let the request pass through unchanged. chain.doFilter(request, response); }
From source file:com.concursive.connect.web.controller.servlets.URLControllerServlet.java
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { LOG.debug("service called"); LOG.debug("requestCharacterEncoding=" + request.getCharacterEncoding()); try {/*w w w. j a va 2 s .co m*/ request.setCharacterEncoding("UTF-8"); } catch (Exception e) { LOG.warn("Unsupported encoding"); } // Check the preferences to see if the correct domain name is being used, else do a redirect ApplicationPrefs prefs = (ApplicationPrefs) request.getSession().getServletContext() .getAttribute("applicationPrefs"); boolean redirect = false; String contextPath = request.getContextPath(); String uri = request.getRequestURI(); String queryString = request.getQueryString(); String path = uri.substring(contextPath.length()) + (queryString == null ? "" : "?" + queryString); LOG.debug("path: " + path); request.setAttribute("requestedURL", path); // It's important the user is using the correct URL for accessing content; // The portal has it's own redirect scheme, this is a another catch all // to see if an old domain name or context is used PortalBean bean = new PortalBean(request); String expectedDomainName = prefs.get(ApplicationPrefs.WEB_DOMAIN_NAME); LOG.debug("expectedDomainName: " + expectedDomainName); LOG.debug("domainName: " + bean.getServerName()); String expectedContext = prefs.get(ApplicationPrefs.WEB_CONTEXT); LOG.debug("expectedContextPath: " + expectedContext); LOG.debug("contextPath: " + contextPath); if (StringUtils.hasText(expectedContext) && !expectedContext.equals(contextPath) || (expectedDomainName != null && path.length() > 0 && !"127.0.0.1".equals(bean.getServerName()) && !"127.0.0.1".equals(expectedDomainName) && !"localhost".equals(bean.getServerName()) && !"localhost".equals(expectedDomainName) && !bean.getServerName().startsWith("10.") && !bean.getServerName().startsWith("172.") && !bean.getServerName().startsWith("192.") && !bean.getServerName().equals(expectedDomainName))) { if (uri.length() > 0 && !uri.substring(1).equals(prefs.get("PORTAL.INDEX"))) { String newUrl = URLFactory.createURL(prefs.getPrefs()) + path; request.setAttribute("redirectTo", newUrl); LOG.debug("redirectTo: " + newUrl); request.removeAttribute(Constants.REQUEST_PAGE_LAYOUT); redirect = true; } } if (redirect) { try { RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/redirect301.jsp"); dispatcher.forward(request, response); } catch (Exception e) { } } else { mapToMVCAction(request, response); } }
From source file:org.slc.sli.dashboard.security.SLIAuthenticationEntryPoint.java
private void completeAuthentication(HttpServletRequest request, HttpServletResponse response, HttpSession session, Object token, boolean cookieFound) throws ServletException, IOException { // Complete Spring security integration SLIPrincipal principal = completeSpringAuthentication((String) token); LOG.info(LOG_MESSAGE_AUTH_COMPLETED, new Object[] { principal.getName(), request.getRemoteAddr() }); // Save the cookie to support sessions across multiple dashboard servers saveCookieWithToken(request, response, (String) token); // AJAX calls OR cookie sessions should not redirect if (isAjaxRequest(request) || cookieFound) { RequestDispatcher dispatcher = request.getRequestDispatcher(request.getServletPath()); dispatcher.forward(request, response); } else {// www . j a va2s .c o m LOG.info(LOG_MESSAGE_AUTH_REDIRECTING, new Object[] { principal.getName(), request.getRemoteAddr() }); response.sendRedirect(request.getRequestURI()); } }
From source file:dk.statsbiblioteket.doms.licensemodule.servlets.ConfigurationServlet.java
private void returnFormPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { RequestDispatcher dispatcher = request.getRequestDispatcher("configuration.jsp"); dispatcher.forward(request, response); return;//from w w w . j a v a 2s .c o m }
From source file:edu.cornell.mannlib.vitro.webapp.controller.jena.JenaCsv2RdfController.java
@Override public void doPost(HttpServletRequest rawRequest, HttpServletResponse response) throws ServletException, IOException { if (!isAuthorizedToDisplayPage(rawRequest, response, SimplePermission.USE_ADVANCED_DATA_TOOLS_PAGES.ACTION)) { return;// w w w .j ava2s . c o m } VitroRequest request = new VitroRequest(rawRequest); if (request.hasFileSizeException()) { forwardToFileUploadError(request.getFileSizeException().getLocalizedMessage(), request, response); return; } Map<String, List<FileItem>> fileStreams = request.getFiles(); FileItem fileStream = fileStreams.get("filePath").get(0); String filePath = fileStreams.get("filePath").get(0).getName(); String actionStr = request.getParameter("action"); actionStr = (actionStr != null) ? actionStr : ""; if ("csv2rdf".equals(actionStr)) { String csvUrl = request.getParameter("csvUrl"); if (!csvUrl.isEmpty() || !filePath.isEmpty()) { String destinationModelNameStr = request.getParameter("destinationModelName"); Model csv2rdfResult = null; try { csv2rdfResult = doExecuteCsv2Rdf(request, fileStream, filePath); } catch (Exception ex) { forwardToFileUploadError(ex.getMessage(), request, response); return; } ModelMaker maker = getModelMaker(request); Boolean csv2rdf = true; JenaIngestUtils utils = new JenaIngestUtils(); List<Model> resultList = new ArrayList<Model>(); resultList.add(csv2rdfResult); Map<String, LinkedList<String>> propertyMap = utils.generatePropertyMap(resultList, maker); request.setAttribute("propertyMap", propertyMap); request.setAttribute("csv2rdf", csv2rdf); request.setAttribute("destinationModelName", destinationModelNameStr); request.setAttribute("title", "URI Select"); request.setAttribute("bodyJsp", CSV2RDF_SELECT_URI_JSP); } else { request.setAttribute("title", "Convert CSV to RDF"); request.setAttribute("bodyJsp", CSV2RDF_JSP); } } RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP); request.setAttribute("css", "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + request.getAppBean().getThemeDir() + "css/edit.css\"/>"); try { rd.forward(request, response); } catch (Exception e) { throw new RuntimeException(e); } }