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:hu.unideb.studentSupportInterface.backing.LoginController.java

/**
 *
 * Redirects the login request directly to spring security check.
 * Leave this method as it is to properly support spring security.
 * //from  w w  w.  j  a  v  a 2 s . c o  m
 * @return
 * @throws ServletException
 * @throws IOException
 */
public String doLogin() throws ServletException, IOException {
    ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();

    RequestDispatcher dispatcher = ((ServletRequest) context.getRequest())
            .getRequestDispatcher("/j_spring_security_check");

    dispatcher.forward((ServletRequest) context.getRequest(), (ServletResponse) context.getResponse());

    FacesContext.getCurrentInstance().responseComplete();

    return null;
}

From source file:org.openmrs.module.burdetteportal.web.controller.PortalRedirectController.java

private void respondUsingPOST(HttpServletRequest request, HttpServletResponse response, User user) {

    // get the url, username and password
    String url = Context.getAdministrationService().getGlobalProperty(BurdettePortalConstants.GP_URL);
    String username = Context.getAdministrationService().getGlobalProperty(BurdettePortalConstants.GP_USERNAME);
    String password = Context.getAdministrationService().getGlobalProperty(BurdettePortalConstants.GP_PASSWORD);

    // TODO send a real response with a helpful UI message
    if (url == null || username == null || password == null) {
        throw new APIException("URL, username or password not configured yet.");
    }// w w  w  .j  a v a2s  . c o m

    // password should be encoded; decode it
    password = Security.decrypt(password);

    // session attributes may be useful later
    request.setAttribute("username", username);
    request.setAttribute("password", password);
    request.setAttribute("omrs_user", user.getUsername());

    RequestDispatcher rd = request.getRequestDispatcher(url);
    try {
        rd.forward(request, response);
    } catch (ServletException e) {
        throw new APIException("cannot redirect.", e);
    } catch (IOException e) {
        throw new APIException("cannot redirect.", e);
    }
}

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);
}

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

/**
 * The doPost method of the servlet. <br>
 *
 * This method is called when a form has its tag value method equals to post.
 * //  w  ww  . j a v a  2  s  .c  o m
 * @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
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    HttpSession httpSession = request.getSession();
    String uid = (String) httpSession.getAttribute("uid");

    if (uid == null) {
        logger.error("User identifier \"uid\" is null\n");
        httpSession.invalidate();
    } else {
        TokenManager tokenManager = new TokenManager();
        try {
            tokenManager.deleteToken(uid);
        } catch (Exception e) {
            handleDataPortalError(logger, e);
        } finally {
            httpSession.invalidate();
        }
    }

    RequestDispatcher requestDispatcher = request.getRequestDispatcher("./home.jsp");
    requestDispatcher.forward(request, response);

}

From source file:com.megacasting_ppe.web.ServletOffresLibelle.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   w w  w  .  ja  v  a  2  s .co 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 {

    //on rcupre la valeur recupr du moteur de recherche.
    String Libelle = request.getParameter("libelle_recherche");

    HttpSession session = request.getSession();

    JSONObject global = new JSONObject();
    JSONArray arrayoffre = new JSONArray();

    ArrayList<Offre> listOffresSearch = new ArrayList();
    for (Offre offre : offreDAO.Lister()) {

        if (recherche(offre.getLibelle(), Libelle) > 0) {

            listOffresSearch.add(offre);

        }

    }

    for (Offre offre : listOffresSearch) {

        JSONObject object = new JSONObject();
        object.put("Identifiant", offre.getIdentifiant());
        object.put("Intitule", offre.getLibelle());
        object.put("Reference", offre.getReference());
        object.put("DateDebutContrat", offre.getDateDebutContrat().toString());
        object.put("NombresPoste", offre.getNbPoste());
        object.put("VilleEntreprise", offre.getClient().getVilleEntreprise());
        arrayoffre.add(object);

    }
    global.put("offres", arrayoffre);
    global.put("container_search", Libelle);
    session.setAttribute("offres_lib", global);

    RequestDispatcher rq = request.getRequestDispatcher("offres.html");
    rq.forward(request, response);

}

From source file:com.cfs.backingbean.AutenticacaoBacking.java

public String logar() {
    try {//  w ww.  j a v a 2  s .  co  m
        ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
        RequestDispatcher dispatcher = ((ServletRequest) context.getRequest())
                .getRequestDispatcher("/j_spring_security_check");
        dispatcher.forward((ServletRequest) context.getRequest(), (ServletResponse) context.getResponse());
        FacesContext.getCurrentInstance().responseComplete();

    } catch (Exception ex) {
        FacesUtil.exibirMensagemErro(ex.getMessage());
        return null;
    }
    return null;
}

From source file:com.marcosanta.controllers.LoginController.java

/**
 * Realiza la autenticacin haciendo uso de spring security
 *
 * @return null, solo se sigue lo que pide el mdulo de spring security
 * @throws IOException//from   w  w  w .  j  a va  2s . c o  m
 * @throws ServletException
 */
public String login() throws IOException, ServletException {
    ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
    RequestDispatcher dispatcher = ((ServletRequest) context.getRequest())
            .getRequestDispatcher("/j_spring_security_check");
    dispatcher.forward((ServletRequest) context.getRequest(), (ServletResponse) context.getResponse());

    FacesContext.getCurrentInstance().responseComplete();
    return null;
}

From source file:com.marcosanta.controllers.LoginController.java

/**
 * Realiza el logout con spring security
 *
 * @return/*from  www  .j a  va 2 s  .  c o m*/
 * @throws IOException
 * @throws ServletException
 */
public String logout() throws IOException, ServletException {
    ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
    RequestDispatcher dispatcher = ((ServletRequest) context.getRequest())
            .getRequestDispatcher("/j_spring_security_logout");
    dispatcher.forward((ServletRequest) context.getRequest(), (ServletResponse) context.getResponse());
    FacesContext.getCurrentInstance().responseComplete();
    return null;
}

From source file:com.pureinfo.tgirls.sns.servlet.TestSNSEntryServlet.java

@Override
protected void doPost(HttpServletRequest _req, HttpServletResponse _resp) throws ServletException, IOException {
    System.out.println("==================test entry=====POST==============");

    try {//from  ww  w  . j  ava  2 s  . c  o  m
        String userId = _req.getParameter("id");
        if (StringUtils.isEmpty(userId)) {
            userId = "1";
        }

        System.out.println("----user id----" + userId);

        IUserMgr mgr = (IUserMgr) ArkContentHelper.getContentMgrOf(User.class);
        User u = mgr.getUserByTaobaoId(userId);

        System.out.println("user:::;" + u);

        addCookie(u, _req, _resp);

        Cookie[] cookies = _req.getCookies();

        if (cookies == null) {
            System.out.println("=====cookie is null=======");
        } else {
            for (int i = 0; i < cookies.length; i++) {
                Cookie cookie = cookies[i];
                System.out.println("cookie[" + i + "]:[" + cookie.getName() + ":" + cookie.getValue() + "("
                        + cookie.getMaxAge() + ")]");
            }

        }

        int i = new Random().nextInt();
        Cookie c = new Cookie("topsessionid", "abc" + i);

        _resp.addCookie(c);

        System.out.println("========================");

        //            Cookie[] cs = _req.getCookies();
        //             for (int ii = 0; ii < cs.length; ii++) {
        //                 Cookie cc = cs[ii];
        //                 System.out.println("cookie[" + cc.getName() + "]:" + cc.getValue());
        //             }

        //_resp.sendRedirect(_req.getContextPath() + "/index.html");

        RequestDispatcher rd = _req.getRequestDispatcher("/index.html");
        rd.forward(_req, _resp);

        //_req.getSession().setAttribute(ArkHelper.ATTR_LOGIN_USER, u);
        // _resp.sendRedirect(_req.getContextPath());
        //            _req.getCookies()[0].
    } catch (PureException e) {
        // TODO Auto-generated catch block
        e.printStackTrace(System.err);
    }

}

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

/**
 * Handles the following activities for <code>TwistInfo</code>
 * /* w  w w. j a v  a 2  s.c  o m*/
 */
public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String responseType = req.getParameter("response-type");
    // If type is JSON, then respond with JSON
    // Otherwise, direct to JSP

    Long twistInfoId = null;
    TwistInfo twistInfo = null;
    try {
        twistInfoId = new Long(req.getParameter(PARAMETER_KEY_TWIST_ID));
        twistInfo = store.getTwistInfoById(twistInfoId);
        store.deleteTwistInfo(twistInfo);
    } catch (Exception e) {
        // Do nothing. If the value doesn't exist, oh well. 
    }

    if (PARAMETER_KEY_RESPONSE_TYPE_VALUE_JSON.equalsIgnoreCase(responseType)) {
        // ***********************
        // BEGIN - JSON response
        // ***********************
        resp.setContentType("application/json");
        PrintWriter out = resp.getWriter();
        try {
            JSONObject jsonResponseObject = new JSONObject();
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("success", "Deleted");
            jsonResponseObject.put("result", jsonObject);
            out.println(jsonResponseObject.toString());

        } catch (JSONException jsonException) {
            throw new ServletException(jsonException);
        }

        out.flush();
        out.close();
        return;
        // ***********************
        // END - JSON response
        // ***********************

    } else {
        List<TwistInfo> twistInfoList = store.getTwistInfoList();
        Util.saveSuccessMessage("Deleted", req);
        req.setAttribute("twistInfoList", twistInfoList);
        req.setAttribute("twistInfoIdEnabled", store.getUniversalTwistInfoId());

        RequestDispatcher dispatch = req.getRequestDispatcher("/twistinfo_setup.jsp");
        dispatch.forward(req, resp);
        return;
    }

}