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:cn.itcast.bbs.controller.BbsServlet.java

private void toNewTopicJsp(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String typeId = request.getParameter("typeId");
    try {/*from  w  w w .  j a  va2s.c o  m*/
        Type type = service.findTypeById(Integer.parseInt(typeId));
        request.setAttribute("type", type);
        request.getRequestDispatcher("/WEB-INF/bbs/addNewTopic.jsp").forward(request, response);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:io.muic.ooc.webapp.servlet.DeleteServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String username = request.getParameter("username");
    boolean confirm = StringUtils.equals(request.getParameter("confirm"), "true");

    User user = userService.getUser(username);

    String currentUser = (String) request.getSession().getAttribute("username");

    if (user != null && !StringUtils.equals(currentUser, username)) {
        if (confirm) {
            userService.removeUser(user);

            response.sendRedirect("/");
        } else {//from   w ww .  j a  va2  s  .c om
            request.setAttribute("user", username);

            RequestDispatcher rd = request.getRequestDispatcher("WEB-INF/remove.jsp");
            rd.include(request, response);
        }
    } else {
        response.sendRedirect("/");
    }
}

From source file:controller.servlet.PostServlet.java

private void upLoad(HttpServletRequest request, HttpServletResponse response, String imagName,
        Boolean isSuccess) throws ServletException, IOException {
    if (isSuccess) {
        request.setAttribute(Constants.RESULT_UPLOAD, "Hnh nh  c ti ln");
        request.setAttribute(Constants.URL_IMAGE, "image/post/" + imagName);
    } else {/*from w w  w .j  a v a  2s .  c om*/
        request.setAttribute(Constants.RESULT_UPLOAD, "Li");
    }
    request.setAttribute(Constants.PAGE, "new-topic");
    request.getRequestDispatcher(Constants.URL_HOME).forward(request, response);
}

From source file:com.arcadian.loginservlet.ViewAssignmentServlet.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        assignmentService = new ViewAssignmentService();
        HttpSession session = request.getSession();
        username = (String) session.getAttribute("username");
        System.out.println("hello");
        ArrayList alstAssignments = assignmentService.getAssignments(username);
        request.setAttribute("alstAssignmentNotice", alstAssignments);

        RequestDispatcher dispatcher = request.getRequestDispatcher("dashboard/viewassignment.jsp");
        dispatcher.forward(request, response);
    }//from   www . ja va  2  s  . c  o m
}

From source file:com.microsoft.azure.oidc.filter.helper.impl.SimpleAuthenticationHelper.java

private void doForwardRequestAction(final HttpServletRequest httpRequest,
        final HttpServletResponse httpResponse, final Token token, final State state)
        throws ServletException, IOException {
    final HttpServletRequest cookieRequestWrapper = clearSessionCoookie(httpRequest, httpResponse, token,
            state);/* w  ww. ja  va  2  s.  c  om*/
    httpRequest.getRequestDispatcher(state.getRequestURI()).forward(cookieRequestWrapper, httpResponse);
}

From source file:eu.earthobservatory.org.StrabonEndpoint.BrowseBean.java

/**
 * Processes the request made from the HTML visual interface of Strabon
 * Endpoint.// www .  j a  v  a2s  .c o m
 * 
 * @param request
 * @param response
 * @throws ServletException
 * @throws IOException
 */
private void processVIEWRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    RequestDispatcher dispatcher;

    String query = URLDecoder.decode(request.getParameter("query"), "UTF-8");
    String format = request.getParameter("format");

    // get stSPARQLQueryResultFormat from given format name
    TupleQueryResultFormat queryResultFormat = stSPARQLQueryResultFormat.valueOf(format);

    if (query == null || format == null || queryResultFormat == null) {
        dispatcher = request.getRequestDispatcher("browse.jsp");
        request.setAttribute(ERROR, PARAM_ERROR);
        dispatcher.forward(request, response);

    } else {
        dispatcher = request.getRequestDispatcher("browse.jsp");
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        request.setAttribute("resource", request.getParameter("resource"));

        try {
            strabonWrapper.query(query, format, bos);
            if (format.equals(Common.getHTMLFormat())) {
                request.setAttribute(RESPONSE, bos.toString());
            } else {
                request.setAttribute(RESPONSE, StringEscapeUtils.escapeHtml(bos.toString()));
            }

        } catch (Exception e) {
            logger.error("[StrabonEndpoint.BrowseBean] Error during querying.", e);
            request.setAttribute(ERROR, e.getMessage());

        } finally {
            dispatcher.forward(request, response);
        }
    }
}

From source file:controller.KlantController.java

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    Klant klant = new Klant();
    klant.setVoornaam(request.getParameter("voornaam"));
    klant.setTussenvoegsel(request.getParameter("tussenvoegsel"));
    klant.setAchternaam(request.getParameter("achternaam"));
    klant.setEmail(request.getParameter("email"));
    String idKlant = request.getParameter("idKlant");
    if (idKlant == null || idKlant.isEmpty()) {
        dao.createKlant(klant);//from   w  w w .  ja  v  a2s .c  o m
    } else {
        klant.setIdKlant(Integer.parseInt(idKlant));
        dao.updateKlant(klant);
    }
    RequestDispatcher view = request.getRequestDispatcher(LIST_KLANT);
    request.setAttribute("klanten", dao.readAlleKlanten());
    view.forward(request, response);
}

From source file:com.sielpe.controller.GestionarCandidatos.java

/**
 * peticion redireccionar editar usuario
 *
 * @param request//from w ww  . j  ava 2s . c om
 * @param response
 * @throws IOException
 * @throws MiExcepcion
 * @throws ServletException
 */
public void redirectEditarCandidato(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    if (request.getParameter("id") != null) {
        int id = Integer.parseInt(request.getParameter("id"));
        Candidato us = facadeDAO.detallesCandidato(id);
        request.setAttribute("candidato", us);
        ArrayList<Eleccion> eleccionesVigentes = (ArrayList) facadeDAO.eleccionesVigentes();
        request.setAttribute("eleccionesVigentes", eleccionesVigentes);
        request.getRequestDispatcher("editarCandidato.jsp").forward(request, response);
    } else {
        actualizarUsuario(request, response);
    }
}

From source file:io.github.benas.todolist.web.servlet.todo.UpdateTodoServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    long todoId = Long.parseLong(request.getParameter("todoId"));
    String title = request.getParameter("title");
    String dueDate = request.getParameter("dueDate");
    String priority = request.getParameter("priority");
    String status = request.getParameter("status");

    Todo todo = todoService.getTodoById(todoId);
    todo.setTitle(title);/* w  w  w .ja  va 2s .c  o m*/
    todo.setDueDate(new Date(dueDate));
    todo.setDone(Boolean.valueOf(status));
    todo.setPriority(Priority.valueOf(priority));
    todoService.update(todo);
    request.getRequestDispatcher("/todos").forward(request, response);

}

From source file:it.smartcommunitylab.aac.oauth.ExtOAuth2SuccessHandler.java

protected void handle(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
        throws IOException, ServletException {

    OAuth2Authentication oauth = (OAuth2Authentication) authentication;
    @SuppressWarnings("unchecked")
    Map<String, Object> details = (Map<String, Object>) oauth.getUserAuthentication().getDetails();
    details = preprocess(details);//  w  ww . j  a va2s.co  m
    try {
        URIBuilder builder = new URIBuilder(getDefaultTargetUrl());
        for (String key : details.keySet()) {
            builder.addParameter(key, details.get(key).toString());
            request.setAttribute(key, details.get(key));
        }
        request.getRequestDispatcher(builder.build().toString()).forward(request, response);
        //         response.sendRedirect("forward:"+builder.build().toString());
        //         getRedirectStrategy().sendRedirect(request, response, builder.build().toString());
    } catch (URISyntaxException e) {
        throw new ServletException(e.getMessage());
    }
}