Example usage for javax.servlet RequestDispatcher forward

List of usage examples for javax.servlet RequestDispatcher forward

Introduction

In this page you can find the example usage for javax.servlet RequestDispatcher forward.

Prototype

public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException;

Source Link

Document

Forwards a request from a servlet to another resource (servlet, JSP file, or HTML file) on the server.

Usage

From source file:com.ss.Controller.T4uGoToScheduleServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from w w w  . j a v  a2 s .c om
 *
 * @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 {
    List<Integer> allScheduleIds = T4uScheduleDAO.getAllScheduleIds();
    List<T4uSchedule> allSchedules = new ArrayList<T4uSchedule>();
    for (int scheduleId : allScheduleIds)
        allSchedules.add(T4uScheduleDAO.getScheduleById(scheduleId));
    Map<Integer, T4uHouse> allHouses = T4uHouseDAO.getAllHouses();
    Map<Integer, T4uMovie> allMovies = T4uMovieDAO.getAllMovies();
    for (Map.Entry<Integer, T4uMovie> entry : allMovies.entrySet()) {
        Integer key = entry.getKey();
        T4uMovie value = entry.getValue();
        value.setAllVersions(T4uVersionDAO.getAllVersions(value));
    }
    HttpSession session = request.getSession(true);
    session.setAttribute(T4uConstants.T4uAllSchedules, allSchedules);
    session.setAttribute(T4uConstants.T4uAllHouses, allHouses);
    session.setAttribute(T4uConstants.T4uAllMovies, allMovies);

    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/schedules.jsp");
    dispatcher.forward(request, response);
}

From source file:com.itesm.test.servlets.TasksServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    RequestDispatcher rd = getServletContext().getRequestDispatcher("/tasks.jsp");
    rd.forward(req, resp);
}

From source file:controllers.ControladorFotoCoin.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request//from   w ww.j a  v  a  2  s .co 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 {
    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);
}

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

private void forward(String url, HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    RequestDispatcher rd = getServletContext().getRequestDispatcher(url);
    rd.forward(request, response);
}

From source file:me.uni.sushilkumar.geodine.util.CuisineHandler.java

/**
 * Processes requests for both HTTP/*from  w ww  .  ja  v a2s .c  o  m*/
 * <code>GET</code> and
 * <code>POST</code> methods.
 *
 * @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, ParseException {
    //response.setContentType("text/html;charset=UTF-8");
    //PrintWriter out = response.getWriter();
    DBConnection con = null;
    String path = request.getRequestURI();
    int index = path.lastIndexOf("/");
    String cuisine = path.substring(index + 1);
    cuisine = cuisine.replace("-", " ");
    con = new DBConnection();
    CuisineObject obj = con.getCuisineData(cuisine);
    String name = obj.getName();
    String country = obj.getCountry();
    String ytid = obj.getYtid();
    ArrayList<String> directions = obj.getDirections();
    ArrayList<String> ingredients = obj.getIngredients();
    request.setAttribute("name", name);
    request.setAttribute("country", country);
    request.setAttribute("directions", directions);
    request.setAttribute("ingredients", ingredients);
    request.setAttribute("ytid", ytid);
    RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/recipe.jsp");
    rd.forward(request, response);

}

From source file:net.swas.explorer.servlet.ms.GetMSConfig.java

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 *///from  w ww.  j a va  2 s  . co  m
@SuppressWarnings("unchecked")
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    JSONObject messageJson = new JSONObject();

    messageJson.put("action", "readMSConfig");
    this.prod.send(messageJson.toJSONString());

    String revMsg = this.cons.getReceivedMessage(request.getServletContext());
    log.info("Received Message :" + revMsg);
    if (revMsg != null) {

        JSONParser parser = new JSONParser();
        JSONObject revJson = null;
        try {

            revJson = (JSONObject) parser.parse(revMsg);
            request.removeAttribute("msConfig");
            request.setAttribute("msConfig", revJson);

        } catch (ParseException e) {

            e.printStackTrace();

        }

    }

    RequestDispatcher rd = request.getRequestDispatcher("/msConfigForm.jsp");
    rd.forward(request, response);

}

From source file:com.mockey.ui.ServiceMergeServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    req.setAttribute("services", Util.orderAlphabeticallyByServiceName(store.getServices()));
    req.setAttribute("plans", store.getServicePlans());

    RequestDispatcher dispatch = req.getRequestDispatcher("service_merge.jsp");

    dispatch.forward(req, resp);
}

From source file:controllers.LoginController.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request//from  w  ww .ja va2  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 {
    response.setContentType("text/html;charset=UTF-8");
    User user = (User) request.getAttribute("user");
    if (user != null) {
        // User has been already registered
        response.sendRedirect(request.getContextPath() + "/home");
    } else {
        // Remove user's session
        HttpSession session = request.getSession(false);
        String error = null;
        if (session != null && (error = (String) session.getAttribute("error")) != null) {
            request.setAttribute("error", error);
            session.removeAttribute("error");
        }
        RequestDispatcher rd = request.getRequestDispatcher("login.jsp");
        rd.forward(request, response);
    }
}

From source file:edu.morgan.server.UploadFile.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {
    RequestDispatcher rd;
    rd = request.getRequestDispatcher("fail.jsp");
    rd.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);//  ww  w .  ja  va 2s  .c  om
    } else {
        klant.setIdKlant(Integer.parseInt(idKlant));
        dao.updateKlant(klant);
    }
    RequestDispatcher view = request.getRequestDispatcher(LIST_KLANT);
    request.setAttribute("klanten", dao.readAlleKlanten());
    view.forward(request, response);
}