Example usage for javax.servlet.http HttpServletRequest getRequestDispatcher

List of usage examples for javax.servlet.http HttpServletRequest getRequestDispatcher

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest 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:dk.itst.oiosaml.sp.service.DispatcherServlet.java

private void handleError(HttpServletRequest request, HttpServletResponse response, Exception e)
        throws ServletException, IOException {
    log.error("Unable to validate Response", e);

    String err = null;/*w  w w  .  j ava  2 s . co  m*/
    if (configuration != null) {
        err = configuration.getString(Constants.PROP_ERROR_SERVLET, null);
    }
    if (err != null) {
        request.setAttribute(Constants.ATTRIBUTE_ERROR, e.getMessage());
        request.setAttribute(Constants.ATTRIBUTE_EXCEPTION, e);
        request.getRequestDispatcher(err).forward(request, response);
    } else {
        VelocityContext ctx = new VelocityContext();
        ctx.put(Constants.ATTRIBUTE_ERROR, e.getMessage());
        ctx.put(Constants.ATTRIBUTE_EXCEPTION, e);

        response.setContentType("text/html");
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);

        String prefix = "/" + getClass().getPackage().getName().replace('.', '/') + "/";
        try {
            engine.mergeTemplate(prefix + "error.vm", ctx, response.getWriter());
        } catch (Exception e1) {
            log.error("Unable to render error template", e1);
            throw new ServletException(e1);
        }
    }

}

From source file:controllers.ChargesControllerServlet.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request/*from  w w w  .  j  a  v a  2 s  .  c om*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String path = request.getPathInfo();
    String url = path;
    if (url == null || url.equals("/")) {
        url = "/WEB-INF/jsp/charges/index.jsp";
        ArrayList charges = models.Charge.all();
        request.setAttribute("charges", charges);
    } else if (url.matches("/new")) {
        url = "/WEB-INF/jsp/charges/new.jsp";
    } else if (url.matches("/\\d+/buy")) {
        url = "/WEB-INF/jsp/charges/buy.jsp";
    } else if (url.matches("/\\d+")) {
        url = "/WEB-INF/jsp/charges/show.jsp";
    }
    request.getRequestDispatcher(url).forward(request, response);
}

From source file:cn.vlabs.umt.ui.servlet.OnlineStorageLoginServlet.java

/**
 * The doPost method of the servlet. <br>
 * //from  www  . j a  v a  2 s  .  c o  m
 * This method is called when a form has its tag value method equals to
 * post.
 * 
 * @param request
 *            the request send by the client to the server
 * @param response
 *            the response send by the server to the client
 * @throws ServletException
 *             if an error occurred
 * @throws IOException
 *             if an error occurred
 */
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String sid = (String) request.getSession(true).getAttribute("_onlineStorageUid");
    sid = sid == null ? this.getSid(request) : sid;
    if (sid != null) {
        String location = null;
        if (onlineStorageURL.indexOf('?') < 0) {
            location = onlineStorageURL + "?sid=" + sid;
        } else {
            location = onlineStorageURL + "&sid=" + sid;
        }
        request.getSession(true).setAttribute("_onlineStorageUid", sid);
        response.sendRedirect(location);
    } else {
        request.getRequestDispatcher("/thirdpartyLostPassword.jsp").forward(request, response);
    }
}

From source file:br.org.indt.ndg.servlets.OpenRosaManagement.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    m_openRosaBD.setPortAndAddress(SystemProperties.getServerAddress());
    String action = request.getParameter(ACTION_PARAM);
    if (action != null) {
        if (SET_AVAILABLE_FOR_USER.equals(action)) {
            dispatchSurveysForUserSelectionPage(request, response);
        } else if (EXPORT_RESULTS_FOR_USER.equals(action)) {
            dispatchExportResultsForUserPage(request, response);
        } else {/*from   w  w w .  jav  a 2  s  . c  o  m*/
            request.setAttribute(PRINT_AVAILABLE_COMMANDS_ATTR, "printAll");
            request.getRequestDispatcher(FORWARD_FILEPATH).forward(request, response);
        }
    } else {
        request.setAttribute(PRINT_AVAILABLE_COMMANDS_ATTR, "printAll");
        request.getRequestDispatcher(FORWARD_FILEPATH).forward(request, response);
    }
}

From source file:edu.lternet.pasta.portal.ProvenanceGraphServlet.java

/**
 * The doPost method of the servlet. <br>
 * /*  w w w .j  av  a2s  .  c om*/
 * This method is called when a form has its tag value method equals to post.
 * 
 * @param request
 *          the request send by the client to the server
 * @param response
 *          the response send by the server to the client
 * @throws ServletException
 *           if an error occurred
 * @throws IOException
 *           if an error occurred
 */
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {
        HttpSession httpSession = request.getSession();
        String uid = (String) httpSession.getAttribute("uid");
        if (uid == null || uid.isEmpty())
            uid = "public";
        String source = request.getParameter("source");
        String derived = request.getParameter("derived");

        if ((source != null) && (derived != null)) {
            request.setAttribute("source", source);
            request.setAttribute("derived", derived);
            RequestDispatcher requestDispatcher = request.getRequestDispatcher(forward);
            requestDispatcher.forward(request, response);
        } else {
            throw new UserErrorException("Package identifier is null.");
        }
    } catch (Exception e) {
        handleDataPortalError(logger, e);
    }
}

From source file:net.thewaffleshop.nimbus.security.ForwardingAuthenticationHandler.java

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {
    // extract account and password
    String password = (String) authentication.getCredentials();
    AccountUser accountUser = (AccountUser) authentication.getPrincipal();
    Account account = accountUser.getAccount();
    // decode the secret key
    SecretKey secretKey = accountAPI.getSecretKey(account, password);
    // store the account and secret key in the session
    HttpSession session = request.getSession();
    session.setAttribute("account", account);
    session.setAttribute("secretKey", secretKey);

    // forward request to success MVC method
    request.getRequestDispatcher("/authenticationSuccess").forward(request, response);
}

From source file:br.com.gamestore.Servlet.ChamadoServlet.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request//from w  w w  .ja v  a2 s  . c  o m
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    /**
     * RECEBE A AO DO USU?RIO
     */
    String acao = request.getParameter("acao");
    Chamado chamado = new Chamado();
    ChamadoDao chamadoDao = new ChamadoDao();

    /**
     * SE A AO SEJA ABRIRCHAMADO, ELE RETORNAR? A TELA DE CHAMADO
     */
    if (acao.equals("abrirchamado")) {

        RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/paginajsp/abrirchamado.jsp");
        dispatcher.forward(request, response);

        /**
         * SE A AO SEJA LISTARCHAMADO, ELE RETORNA A LISTA DE CHAMADOS
         */
    } else if (acao.equals("listarchamado")) {

        try {
            List<Chamado> listachamado = chamadoDao.listarTodosChamados();
            request.setAttribute("listachamado", listachamado);

            RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/paginajsp/listachamado.jsp");
            dispatcher.forward(request, response);

        } catch (SQLException ex) {
            Logger.getLogger(ChamadoServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
        /**
         * SE A AO SEJA ATENDER CHAMADO, OS DADOS DO CHAMADO SO LEVADO, PARA A TELA
         * ATENDER CHAMADO
        */
    } else if (acao.equals("atenderchamado")) {

        try {

            List<Chamado> listachamado;
            listachamado = chamadoDao.listarTodosChamados();
            request.setAttribute("listachamado", listachamado);
            RequestDispatcher dispatcher = request
                    .getRequestDispatcher("/WEB-INF/paginajsp/atenderchamado.jsp");
            dispatcher.forward(request, response);
        } catch (PersistenceException | SQLException ex) {
            Logger.getLogger(ChamadoServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
        /**
         * SE A AO EXCLUIR, ELE EXCLUIR O CHAMADO 
         */
    } else if (acao.equals("excluir")) {
        String id = request.getParameter("id");
        chamado.setId(Integer.parseInt(id));
        if (id != null) {
            chamadoDao.excluir(chamado);

            response.sendRedirect("ChamadoServlet?acao=atenderchamado");
        }
        /**
         * SE A AO ATUALIZAR, ELE ATUALIZAR? AS INFORMAES DO CHAMADO
         */
    } else if (acao.equals("atualizarchamado")) {
        String id = request.getParameter("id");
        chamado = chamadoDao.buscarPorId(Integer.parseInt(id));
        request.setAttribute("chamado", chamado);
        RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/paginajsp/abrirchamado.jsp");
        dispatcher.forward(request, response);

        /**
         * SETA OS OBJETOS EM BRANCO NA TELA DE CHAMADO, ASSIM QUE O MESMO FOR ABERTO
         */
    } else if (acao.equals("cadastro")) {

        chamado.setEmail("");
        chamado.setTelefone("");
        chamado.setAssunto("");
        chamado.setComentario("");

        RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/paginajsp/abrirchamado.jsp");
        dispatcher.forward(request, response);

    }
}

From source file:cn.itcast.bbs.controller.BbsServlet.java

private void toReplyJsp(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {/*  w ww. ja va 2s . c o m*/
        int topicId = 0;
        if (request.getParameter("topicId") != null) {
            topicId = Integer.parseInt(request.getParameter("topicId"));
        }
        request.setAttribute("topicId", topicId);
        request.getRequestDispatcher("/WEB-INF/bbs/addNewReply.jsp").forward(request, response);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:sg.edu.ntu.hrms.web.action.UploadEmp.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from   w  ww .j  av  a  2s . com*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    boolean hasAccess = false;
    response.setContentType("text/html;charset=UTF-8");
    String action = request.getParameter("action");
    System.out.println("action: " + action);
    HttpSession session = request.getSession();
    HashMap accessTab = (HashMap) session.getAttribute("access");
    AccessDTO access = (AccessDTO) accessTab.get("System Log");
    if (access.getAccess() >= 1) {
        hasAccess = true;
    }
    if (!hasAccess) {
        RequestDispatcher dispatcher = request.getRequestDispatcher("/noAccess.jsp");
        dispatcher.forward(request, response);
    } else {
        if (action == null || action.isEmpty()) {
            FileItemFactory factory = new DiskFileItemFactory();
            ServletFileUpload upload = new ServletFileUpload(factory);
            //PriceDAO priceDAO = new PriceDAO();
            WebApplicationContext ctx = WebApplicationContextUtils
                    .getRequiredWebApplicationContext(getServletContext());

            try {
                List<FileItem> fields = upload.parseRequest(request);
                EmployeeEditService svc = (EmployeeEditService) ctx.getBean(EmployeeEditService.class);
                svc.uploadEmp(fields);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {

                //System.out.println("redirect to employee");
                response.sendRedirect("employee.action");
                /*
                RequestDispatcher dispatcher = request.getRequestDispatcher("/employee");
                //request.setAttribute(Constants.TITLE, "Home");
                dispatcher.forward(request, response);
                */

            }
        } else {
            RequestDispatcher dispatcher = request.getRequestDispatcher("/uploadEmp.jsp");
            //request.setAttribute(Constants.TITLE, "Home");
            dispatcher.forward(request, response);

        }
    }
}

From source file:controllers.ControladorFotoCoin.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request/*  w  w  w.j  ava2 s. c  om*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String userPath = request.getServletPath();
    //pasar a jspf 
    if (userPath.equals("/ControladorFotoCoin")) {
        int idMatch = Integer.parseInt(request.getParameter("idMatch"));
        request.setAttribute("idMatch", idMatch);
        userPath = "enviarFotoCoincidente";

    } else if (userPath.equals("/Notificar")) {
        // int idMatch = Integer.parseInt(request.getParameter("idUsuario")); cuando se genere el match

    }

    String url = "WEB-INF/view/" + userPath + ".jspf";
    RequestDispatcher rd = request.getRequestDispatcher(url);
    rd.forward(request, response);
}