Example usage for javax.servlet ServletContext getRequestDispatcher

List of usage examples for javax.servlet ServletContext getRequestDispatcher

Introduction

In this page you can find the example usage for javax.servlet ServletContext getRequestDispatcher.

Prototype

public RequestDispatcher getRequestDispatcher(String path);

Source Link

Document

Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path.

Usage

From source file:uk.ac.ox.oucs.vle.SchedulerTool.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    ServletContext context = getServletContext();
    List<JobDetailWrapper> jobDetailWrapperList = processRefreshJobs();

    request.setAttribute(Tool.NATIVE_URL, Tool.NATIVE_URL);
    request.setAttribute("jobDetailList", jobDetailWrapperList);

    request.setAttribute("skinRepo", serverConfigurationService.getString("skin.repo", "/library/skin"));

    request.setAttribute("skinDefault", serverConfigurationService.getString("skin.default", "default"));

    RequestDispatcher dispatcher = context.getRequestDispatcher("/static/quartz.jsp");
    dispatcher.forward(request, response);
}

From source file:com.openkm.servlet.admin.CheckTextExtractionServlet.java

@SuppressWarnings("unchecked")
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    log.debug("doPost({}, {})", request, response);
    request.setCharacterEncoding("UTF-8");
    updateSessionManager(request);/* w  w w .  j  av a2 s . com*/
    InputStream is = null;

    try {
        if (ServletFileUpload.isMultipartContent(request)) {
            FileItemFactory factory = new DiskFileItemFactory();
            ServletFileUpload upload = new ServletFileUpload(factory);
            List<FileItem> items = upload.parseRequest(request);
            String docUuid = null;
            String repoPath = null;
            String text = null;
            String error = null;
            String mimeType = null;
            String extractor = null;

            for (Iterator<FileItem> it = items.iterator(); it.hasNext();) {
                FileItem item = it.next();

                if (item.isFormField()) {
                    if (item.getFieldName().equals("docUuid")) {
                        docUuid = item.getString("UTF-8");
                    } else if (item.getFieldName().equals("repoPath")) {
                        repoPath = item.getString("UTF-8");
                    }
                } else {
                    is = item.getInputStream();
                    String name = FilenameUtils.getName(item.getName());
                    mimeType = MimeTypeConfig.mimeTypes.getContentType(name.toLowerCase());

                    if (!name.isEmpty() && item.getSize() > 0) {
                        docUuid = null;
                        repoPath = null;
                    } else if (docUuid.isEmpty() && repoPath.isEmpty()) {
                        mimeType = null;
                    }
                }
            }

            if (docUuid != null && !docUuid.isEmpty()) {
                repoPath = OKMRepository.getInstance().getNodePath(null, docUuid);
            }

            if (repoPath != null && !repoPath.isEmpty()) {
                String name = PathUtils.getName(repoPath);
                mimeType = MimeTypeConfig.mimeTypes.getContentType(name.toLowerCase());
                is = OKMDocument.getInstance().getContent(null, repoPath, false);
            }

            long begin = System.currentTimeMillis();

            if (is != null) {
                if (!MimeTypeConfig.MIME_UNDEFINED.equals(mimeType)) {
                    TextExtractor extClass = RegisteredExtractors.getTextExtractor(mimeType);

                    if (extClass != null) {
                        try {
                            extractor = extClass.getClass().getCanonicalName();
                            text = RegisteredExtractors.getText(mimeType, null, is);
                        } catch (Exception e) {
                            error = e.getMessage();
                        }
                    } else {
                        extractor = "Undefined text extractor";
                    }
                }
            }

            ServletContext sc = getServletContext();
            sc.setAttribute("docUuid", docUuid);
            sc.setAttribute("repoPath", repoPath);
            sc.setAttribute("text", text);
            sc.setAttribute("time", System.currentTimeMillis() - begin);
            sc.setAttribute("mimeType", mimeType);
            sc.setAttribute("error", error);
            sc.setAttribute("extractor", extractor);
            sc.getRequestDispatcher("/admin/check_text_extraction.jsp").forward(request, response);
        }
    } catch (DatabaseException e) {
        sendErrorRedirect(request, response, e);
    } catch (FileUploadException e) {
        sendErrorRedirect(request, response, e);
    } catch (PathNotFoundException e) {
        sendErrorRedirect(request, response, e);
    } catch (AccessDeniedException e) {
        sendErrorRedirect(request, response, e);
    } catch (RepositoryException e) {
        sendErrorRedirect(request, response, e);
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:com.ikon.servlet.admin.OmrServlet.java

/**
 * New omr template// w  w w .  j  a  v  a  2s. c o  m
 */
private void create(String userId, HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, DatabaseException, ParseException, RepositoryException {
    log.debug("create({}, {}, {})", new Object[] { userId, request, response });
    ServletContext sc = getServletContext();
    Omr om = new Omr();
    sc.setAttribute("action", WebUtils.getString(request, "action"));
    sc.setAttribute("om", om);
    sc.setAttribute("properties", PropertyGroupUtils.getAllGroupsProperties());
    sc.getRequestDispatcher("/admin/omr_edit.jsp").forward(request, response);
    log.debug("create: void");
}

From source file:fr.mby.portal.web.controller.PortalController.java

/**
 * Perform internal rendering./*from   w w  w  . ja v  a2 s .  c o  m*/
 * 
 * @param request
 * @param response
 * @param view
 * @param appsToRender
 * @throws ServletException
 * @throws IOException
 */
protected String preRenderApp(final HttpServletRequest request, final HttpServletResponse response,
        final IApp appToRender) throws ServletException, IOException {
    String appContent = "";

    if (appToRender != null) {
        final ServletContext loginContext = this.servletContext.getContext(appToRender.getWebPath());
        if (loginContext != null) {
            final Writer sout = new StringWriter(1024);

            final OpaHttpServletRequest opaRequest = new OpaHttpServletRequest(request, appToRender);
            final SwallowingHttpServletResponse swallowingResponse = new SwallowingHttpServletResponse(response,
                    sout, "UTF-8");
            loginContext.getRequestDispatcher("/").forward(opaRequest, swallowingResponse);
            final String appRendered = sout.toString();

            appContent = this.stripHeaders(appRendered);
        }
    }

    return appContent;
}

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 . ja  va  2s. c  o m
        RequestDispatcher dispatcher = context.getRequestDispatcher(PDF_ERROR_PAGE);
        dispatcher.forward(request, response);
    }
}

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 {/*from w  w w.  j  a  v a 2 s.  co m*/
        RequestDispatcher dispatcher = context.getRequestDispatcher(PDF_PROVIDE_PAGE);
        dispatcher.forward(request, response);
    }
}

From source file:com.ikon.servlet.admin.OmrServlet.java

/**
 * check//from   w  w w .  ja va  2 s. c om
 */
private void check(String userId, HttpServletRequest request, HttpServletResponse response)
        throws DatabaseException, ServletException, IOException {
    ServletContext sc = getServletContext();
    long omId = WebUtils.getLong(request, "om_id");
    sc.setAttribute("action", WebUtils.getString(request, "action"));
    sc.setAttribute("om", OmrDAO.getInstance().findByPk(omId));
    sc.setAttribute("results", null);
    sc.getRequestDispatcher("/admin/omr_check.jsp").forward(request, response);
    log.debug("check: void");
}

From source file:fr.mby.portal.web.controller.PortalController.java

/**
 * Perform internal rendering.//from  w  w  w .  j ava2 s.com
 * 
 * @param request
 * @param response
 * @param view
 * @param appsToRender
 * @throws ServletException
 * @throws IOException
 */
protected void renderApp(final HttpServletRequest request, final HttpServletResponse response,
        final ModelAndView view, final List<IApp> appsToRender) throws ServletException, IOException {
    final Map<IApp, String> appsRendered = new HashMap<IApp, String>(8);

    if (appsToRender != null) {
        for (final IApp app : appsToRender) {
            final ServletContext loginContext = this.servletContext.getContext(app.getWebPath());
            if (loginContext != null) {
                final Writer sout = new StringWriter(1024);

                final OpaHttpServletRequest opaRequest = new OpaHttpServletRequest(request, app);
                final SwallowingHttpServletResponse swallowingResponse = new SwallowingHttpServletResponse(
                        response, sout, "UTF-8");
                loginContext.getRequestDispatcher("/").forward(opaRequest, swallowingResponse);
                final String appRendered = sout.toString();

                final String appContent = this.stripHeaders(appRendered);

                appsRendered.put(app, appContent);
            }
        }
    }

    view.addObject(PortalController.APPS_RENDERED, appsRendered);
}

From source file:com.ikon.servlet.admin.LanguageServlet.java

/**
 * Delete language/*from w  w w.  j  a  va 2 s .  c  o  m*/
 */
private void delete(String userId, HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, DatabaseException {
    log.debug("delete({}, {}, {})", new Object[] { userId, request, response });

    ServletContext sc = getServletContext();
    String lgId = WebUtils.getString(request, "lg_id");
    sc.setAttribute("action", WebUtils.getString(request, "action"));
    sc.setAttribute("persist", true);
    sc.setAttribute("lg", LanguageDAO.findByPk(lgId));
    sc.getRequestDispatcher("/admin/language_edit.jsp").forward(request, response);

    log.debug("delete: void");
}

From source file:com.ikon.servlet.admin.LanguageServlet.java

/**
 * Edit language//from   w ww . j a  v  a  2s. c o m
 */
private void edit(String userId, HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, DatabaseException {
    log.debug("edit({}, {}, {})", new Object[] { userId, request, response });

    ServletContext sc = getServletContext();
    String lgId = WebUtils.getString(request, "lg_id");
    sc.setAttribute("action", WebUtils.getString(request, "action"));
    sc.setAttribute("persist", true);
    sc.setAttribute("lg", LanguageDAO.findByPk(lgId));
    sc.getRequestDispatcher("/admin/language_edit.jsp").forward(request, response);

    log.debug("edit: void");
}