List of usage examples for javax.servlet ServletContext getRequestDispatcher
public RequestDispatcher getRequestDispatcher(String path);
From source file:password.pwm.http.servlet.ConfigGuideServlet.java
static void forwardToJSP(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException { final HttpServletRequest req = pwmRequest.getHttpServletRequest(); final ServletContext servletContext = req.getSession().getServletContext(); final ConfigGuideBean configGuideBean = pwmRequest.getPwmSession().getSessionBean(ConfigGuideBean.class); String destURL = '/' + PwmConstants.URL_JSP_CONFIG_GUIDE; destURL = destURL.replace("%1%", configGuideBean.getStep().toString().toLowerCase()); servletContext.getRequestDispatcher(destURL).forward(req, pwmRequest.getPwmResponse().getHttpServletResponse()); }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { ServletContext context = getServletContext(); RequestDispatcher dispatcher = context.getRequestDispatcher("/myServlet"); dispatcher.forward(req, res);/*from w ww . ja v a 2s . co m*/ }
From source file:org.eclipse.skalli.view.internal.servlet.AuthenticationServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (request.getUserPrincipal() != null) { // principal provided, go back to calling page String returnUrl = (String) request.getParameter(PARAM_RETURNURL); if (StringUtils.isBlank(returnUrl)) { returnUrl = "/"; //$NON-NLS-1$ }//from w ww .j a v a2 s. c om response.sendRedirect(returnUrl); } else { ServletContext context = getServletContext(); RequestDispatcher dispatcher = context.getRequestDispatcher(JSP_LOGIN); dispatcher.forward(request, response); } }
From source file:org.xchain.namespaces.servlet.ForwardCommand.java
public boolean execute(JXPathContext context) throws Exception { ServletContext servletContext = getServletContext(context); RequestDispatcher dispatcher = servletContext.getRequestDispatcher(getPath(context)); dispatcher.forward(getRequest(context), getResponse(context)); return false; }
From source file:com.openkm.servlet.HtmlPreviewServlet.java
/** * /* w ww . j a v a 2s. com*/ */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { log.debug("doGet({}, {})", request, response); String uuid = WebUtils.getString(request, "uuid"); InputStream fis = null; try { fis = OKMDocument.getInstance().getContent(null, uuid, false); StringWriter writer = new StringWriter(); IOUtils.copy(fis, writer, "UTF-8"); String content = writer.getBuffer().toString(); ServletContext sc = getServletContext(); sc.setAttribute("content", content); sc.getRequestDispatcher("/html_preview.jsp").forward(request, response); } catch (PathNotFoundException e) { sendErrorRedirect(request, response, e); } catch (AccessDeniedException e) { sendErrorRedirect(request, response, e); } catch (RepositoryException e) { sendErrorRedirect(request, response, e); } catch (DatabaseException e) { sendErrorRedirect(request, response, e); } finally { IOUtils.closeQuietly(fis); } }
From source file:com.openkm.servlet.admin.LogCatServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); String action = WebUtils.getString(request, "action"); updateSessionManager(request);/* w w w .jav a 2 s . c o m*/ if (action.equals("view")) { view(request, response); } else if (action.equals("purge")) { purge(request, response); } else if (action.equals("download")) { download(request, response); } else if (action.equals("list") || action.equals("")) { list(request, response); } else { ServletContext sc = getServletContext(); sc.getRequestDispatcher("/admin/logcat.jsp").forward(request, response); } }
From source file:forumbox.PostingnewpostServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssms"); Date date = new Date(); String id = dateFormat.format(date); //response.addHeader("Access-Control-Allow-Origin", "*"); PrintWriter out = response.getWriter(); String typed = request.getParameter("userInput"); //getting the parameter which was sent by the client String[] data = new String[3]; data = typed.split("/"); // out.print(data[0]); String username = data[0];/*from w ww.j av a2 s . c o m*/ String title = data[1]; String description = data[2]; filewrite("/home/dinalidabarera/NetBeansProjects/NewFolder/forum4/admin01/post/", username, title, description, response, id); //ompare each name in the names array with the user input pattern and when a matching name is found send that in the response ServletContext sc = getServletContext(); RequestDispatcher view = sc.getRequestDispatcher("/addPost.jsp"); view.forward(request, response); }
From source file:com.emc.plants.web.servlets.ImageServlet.java
/** * Request dispatch.//w ww . ja v a 2 s. co m */ private void requestDispatch(ServletContext ctx, HttpServletRequest req, HttpServletResponse resp, String page) throws ServletException, IOException { ctx.getRequestDispatcher("/" + page).include(req, resp); }
From source file:org.uhp.portlets.news.publisher.ItemServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { final ApplicationContext context = getApplicationContext(); final FeedService feedService = (FeedService) context.getBean("feedService"); if (feedService == null) throw new ServletException(new IllegalStateException("feedService == null")); HttpSession session = request.getSession(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("doGet: sesion uid=" + session.getAttribute(NewsConstants.UID) + " remote user=" + request.getRemoteUser()); }//from w w w. j a v a 2 s.c o m final boolean isProtected = request.getServletPath().contains(Constants.PRIVATE_ACCESS) ? true : false; String jspView = NO_ITEM_VIEW; String msgKey = ""; switch (Integer.parseInt(request.getParameter("c"))) { case Constants.VIEW_ITEM: String itemId = request.getParameter("itemID"); if (itemId != null) { final ItemV iv = feedService.getItem(Long.valueOf(itemId), isProtected); if (iv != null) { request.setAttribute("itemV", iv); List<String> usersUid = new ArrayList<String>(); usersUid.add(iv.getItem().getPostedBy()); usersUid.add(iv.getItem().getLastUpdatedBy()); request.setAttribute(org.uhp.portlets.news.web.support.Constants.ATT_USER_LIST, feedService.getUsersByListUid(usersUid)); jspView = VIEW_ITEM; } else { LOGGER.debug("Item with id " + itemId + " not found !"); //response.sendError(HttpServletResponse.SC_NOT_FOUND, "Item doesn't exist"); msgKey = "news.alert.notFoundItem"; } } break; case Constants.VIEW_ITEMS: final String uid = request.getRemoteUser(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("View list items: remote user=" + request.getRemoteUser()); } if (!isProtected || uid == null) { jspView = NO_ITEM_VIEW; msgKey = "news.alert.noAccessToSecureItem"; } else { request.setAttribute("itemsS", feedService.getItems(Long.valueOf(request.getParameter("tID")), Integer.parseInt(request.getParameter("s")), uid)); jspView = VIEW_ITEMS; } break; default: msgKey = "news.alert.notAuthorizedAction"; break; } final ServletContext app = getServletContext(); final RequestDispatcher dispatcher = app.getRequestDispatcher(jspView); if (!msgKey.equals("")) { request.setAttribute(org.uhp.portlets.news.web.support.Constants.MSG_ERROR, msgKey); } dispatcher.forward(request, response); }
From source file:se.inera.certificate.proxy.mappings.local.LocalDispatcher.java
@Override public void dispatch(HttpServletRequest request, HttpServletResponse response) { // Request path without servlet context path. String requestPath = getPath(request); // The new path to forward to including the new servlet context path. String newUri = joinFragments(localMapping.getMappedPath(), substringAfter(requestPath, localMapping.getContext())); // The context path of the 'forwarded to' servlet. String servletContextPath = getFirstSegment(newUri); // Servlet context of the 'forwarded to' servlet. ServletContext context = request.getServletContext().getContext(servletContextPath); // Get a request dispatcher for the new URL. RequestDispatcher requestDispatcher = context .getRequestDispatcher(StringUtils.substringAfter(newUri, servletContextPath)); LocalRequestWrapper w = new LocalRequestWrapper(request); for (Map.Entry<String, String> header : getRequestContext().getHeaders(request).entrySet()) { w.addHeader(header.getKey(), header.getValue()); }//from w ww . j a v a 2 s. co m try { requestDispatcher.forward(w, response); } catch (ServletException e) { Throwables.propagate(e); } catch (IOException e) { Throwables.propagate(e); } }