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:io.github.benas.todolist.web.servlet.user.account.UpdateAccountServlet.java

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

    String name = request.getParameter("name");
    String email = request.getParameter("email");

    HttpSession session = request.getSession();
    User user = (User) session.getAttribute(TodoListUtils.SESSION_USER);

    if (isAlreadyUsed(email) && isDifferent(email, user.getEmail())) {
        request.setAttribute("error",
                MessageFormat.format(resourceBundle.getString("account.email.alreadyUsed"), email));
        request.setAttribute("user", user);
        request.getRequestDispatcher(ACCOUNT_PAGE).forward(request, response);
        return;/*from w w  w  .  j av  a 2 s  .co m*/
    }

    user.setName(name);
    user.setEmail(email);
    userService.update(user);
    request.setAttribute("updateProfileSuccessMessage",
            resourceBundle.getString("account.profile.update.success"));
    request.getRequestDispatcher("/user/account").forward(request, response);

}

From source file:Controller.CreateTemplate.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request/*from w ww. jav 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 {
    ArrayList<String> finalHostnames = new ArrayList<String>();
    /* Rcupration de la session depuis la requte */
    HttpSession webSession = request.getSession();
    String user = (String) webSession.getAttribute(ATT_SESSION_EMAIL);
    System.out.println("***************USER : " + user);
    finalHostnames = data.GetAllFinalHostnames(user);
    request.setAttribute("containers", finalHostnames);
    request.getRequestDispatcher("createTemplate.jsp").forward(request, response);
}

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

/**
 * The doPost method of the servlet. <br>
 * /*from  ww  w. 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 mapSearchResults = null;
    HttpSession httpSession = request.getSession();

    String uid = (String) httpSession.getAttribute("uid");
    if (uid == null || uid.isEmpty())
        uid = "public";

    String queryText = (String) httpSession.getAttribute("queryText");
    mapSearchResults = executeQuery(uid, queryText);

    request.setAttribute("mapSearchResults", mapSearchResults);
    RequestDispatcher requestDispatcher = request.getRequestDispatcher(forward);
    requestDispatcher.forward(request, response);
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.jena.RDFUploadController.java

private void forwardToFileUploadError(String errrorMsg, HttpServletRequest req, HttpServletResponse response)
        throws ServletException {
    VitroRequest vreq = new VitroRequest(req);
    req.setAttribute("title", "RDF Upload Error ");
    req.setAttribute("bodyJsp", "/jsp/fileUploadError.jsp");
    req.setAttribute("errors", errrorMsg);

    RequestDispatcher rd = req.getRequestDispatcher(Controllers.BASIC_JSP);
    req.setAttribute("css", "<link rel=\"stylesheet\" type=\"text/css\" href=\""
            + vreq.getAppBean().getThemeDir() + "css/edit.css\"/>");
    try {//from  ww  w . j av a2s.c o  m
        rd.forward(req, response);
    } catch (IOException e1) {
        log.error(e1);
        throw new ServletException(e1);
    }
    return;
}

From source file:com.parallax.server.blocklyprop.servlets.PasswordResetServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String token = req.getParameter("token");
    String email = req.getParameter("email");
    req.setAttribute("token", token == null ? "" : token);
    req.setAttribute("email", email == null ? "" : email);
    String password = req.getParameter("password");
    String confirmPassword = req.getParameter("confirmpassword");
    if (Strings.isNullOrEmpty(token) || Strings.isNullOrEmpty(email) || Strings.isNullOrEmpty(password)
            || Strings.isNullOrEmpty(confirmPassword)) {
        req.getRequestDispatcher("WEB-INF/servlet/password-reset/do-reset.jsp").forward(req, resp);
    } else {/*from  w  w w. j  a  v a  2  s .co m*/
        try {
            if (cloudSessionLocalUserService.doPasswordReset(token, email, password, confirmPassword)) {
                showTextilePage(req, resp, PasswordResetPage.RESET_DONE);
                //req.getRequestDispatcher("WEB-INF/servlet/password-reset/reset-done.jsp").forward(req, resp);
            } else {
                req.setAttribute("invalidToken", "Invalid token");
                req.getRequestDispatcher("WEB-INF/servlet/password-reset/do-reset.jsp").forward(req, resp);
            }
        } catch (UnknownUserException ex) {
            req.setAttribute("invalidToken", "Unknown email");
            req.getRequestDispatcher("WEB-INF/servlet/password-reset/do-reset.jsp").forward(req, resp);
        } catch (PasswordVerifyException ex) {
            req.setAttribute("passwordsDontMatch", "Passwords do not match");
            req.getRequestDispatcher("WEB-INF/servlet/password-reset/do-reset.jsp").forward(req, resp);
        } catch (ServerException se) {
            req.setAttribute("server-error", "Server exception");
            req.getRequestDispatcher("WEB-INF/servlet/password-reset/do-reset.jsp").forward(req, resp);
        } catch (PasswordComplexityException pce) {
            req.setAttribute("passwordComplexity", "Password is not complex enough");
            req.getRequestDispatcher("WEB-INF/servlet/password-reset/do-reset.jsp").forward(req, resp);
        } catch (WrongAuthenticationSourceException ex) {
            log.warn("Trying to change password of non local user!");
            req.setAttribute("server-error", "Server exception");
            req.getRequestDispatcher("WEB-INF/servlet/password-reset/do-reset.jsp").forward(req, resp);
        }
    }
}

From source file:com.gigglinggnus.controllers.ModifyAppointmentController.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    EntityManager em = (EntityManager) request.getSession().getAttribute("em");

    Clock clk = (Clock) (request.getSession().getAttribute("clock"));
    String userId = request.getParameter("u");
    String examId = request.getParameter("e");
    User student = em.find(User.class, userId);
    Exam exam = em.find(Exam.class, examId);
    Appointment appt = student.getAppointmentByExam(exam);

    request.setAttribute("appt", appt);

    RequestDispatcher rd = request.getRequestDispatcher("/admin/modify-apmt.jsp");
    rd.forward(request, response);/* ww w  .  ja  v  a2  s .  c  om*/
}

From source file:com.luis.controllers.ServletController.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from w w  w  .jav  a2 s  .  c  o  m
 *
 * @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 {
    response.setContentType("text/html;charset=UTF-8");

    BeanDatosExcel datosExcel = new BeanDatosExcel();
    Excel mi_clase_excel = new Excel();
    String ruta = mi_clase_excel.guardarArchivo(request);
    if (!ruta.equals("-1")) {
        datosExcel.setMiExcel(mi_clase_excel.leerExcel(ruta));
        System.out.println("------------------------********************---------");
        if (datosExcel.getMiExcel() != null) {

            request.setAttribute("datosExcel", datosExcel);
            request.getRequestDispatcher("recepcionExcel.jsp").forward(request, response);
        } else {
            request.getRequestDispatcher("salida.jsp").forward(request, response);
        }
    } else {
        System.out.println("Noooooooooooooooooooooooooooooooooooooooooooop");
        request.getRequestDispatcher("salida.jsp").forward(request, response);
    }
}

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

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // do login post logic
    // extract username and password from request
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    if (!StringUtils.isBlank(username) && !StringUtils.isBlank(password)) {
        if (securityService.authenticate(username, password, request)) {
            response.sendRedirect("/");
        } else {//from ww w.ja v a2s .  co m
            String error = "Wrong username or password.";
            request.setAttribute("error", error);
            RequestDispatcher rd = request.getRequestDispatcher("WEB-INF/login.jsp");
            rd.include(request, response);
        }
    } else {
        String error = "Username or password is missing.";
        request.setAttribute("error", error);
        RequestDispatcher rd = request.getRequestDispatcher("WEB-INF/login.jsp");
        rd.include(request, response);
    }

    // check username and password against database
    // if valid then set username attribute to session via securityService
    // else put error message to render error on the login form

}

From source file:org.yestech.lib.web.HtmlWriter.java

@Override
public void writeTo(Object obj, Class type, Type genericType, Annotation[] annotations, MediaType mediaType,
        MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
    HttpServletRequest request = ResteasyProviderFactory.getContextData(HttpServletRequest.class);
    HttpServletResponse response = ResteasyProviderFactory.getContextData(HttpServletResponse.class);
    try {//  w ww  .java 2 s  .com
        Location location = AnnotationUtil.getAnnotation(Location.class, annotations);
        if (location == null || StringUtils.isBlank(location.value())) {
            throw new RuntimeException("A Location annotation must be supplied and value must be supplied...");
        }
        if (obj != null) {
            request.setAttribute(location.modelKey(), obj);
        }
        RequestDispatcher requestDispatcher = request.getRequestDispatcher(location.value());

        requestDispatcher.forward(request, response);
    } catch (ServletException ex) {
        throw new WebApplicationException(ex);
    }
}

From source file:com.netcracker.tss.web.servlet.customer.CustomerMMGServiceServlet.java

private void redirectToTaxiOrder(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    request.getSession().removeAttribute("taxiOrder");
    UserBeanLocal userBeanLocal = getUserBean(request);
    request.setAttribute("personal_addr", userBeanLocal.toPersonalAddress(UserUtils.findCurrentUser()));
    request.setAttribute("pageContent", "content/customer-mmgService.jsp");
    request.setAttribute("pageType", "mmgService");
    request.getRequestDispatcher("/WEB-INF/views/customer/customer-template.jsp").forward(request, response);
}