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:net.hillsdon.reviki.web.dispatching.impl.ResourceHandlerImpl.java

public View handle(final ConsumedPath path, final HttpServletRequest request,
        final HttpServletResponse response) throws Exception {
    if (!path.hasNext()) {
        throw new NotFoundException();
    }//  w  ww  .  jav a  2s  .  co m

    StringBuilder sb = new StringBuilder("/resources");

    while (path.hasNext()) {
        sb.append("/");
        sb.append(URIUtil.encodeWithinPath(path.next()));
    }

    final String resource = sb.toString();

    return new View() {
        public void render(final HttpServletRequest request, final HttpServletResponse response)
                throws Exception {
            RequestDispatcher requestDispatcher = request.getRequestDispatcher(resource);
            requestDispatcher.forward(request, response);
        }
    };
}

From source file:de.fau.amos.FileDownload.java

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

    String fileName = request.getParameter("downloadFileName");

    //creates a file containing the values of the requested SQL query 
    System.out.println("create file " + fileName + "");
    ArrayList<ArrayList<String>> data = SQL.query("select * from plants");
    createCsvFile(data, fileName);/*from  www.ja va  2 s .c  o m*/

    File file = new File(System.getProperty("userdir.location"), fileName);

    if (fileName == null || !file.exists()) {
        request.getRequestDispatcher("/intern/funktion3.jsp").forward(request, response);
        return;
    }

    response.setHeader("Content-Length", String.valueOf(file.length()));
    response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");

    InputStream input = new BufferedInputStream(new FileInputStream(file), 1024 * 10);
    OutputStream output = new BufferedOutputStream(response.getOutputStream(), 1024 * 10);

    byte[] buffer = new byte[1024 * 10];
    int length;
    while ((length = input.read(buffer)) > 0) {
        output.write(buffer, 0, length);
    }

    output.flush();
    output.close();
    input.close();

}

From source file:org.keycloak.example.ProductServiceAccountServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String reqUri = req.getRequestURI();
    if (reqUri.endsWith("/login")) {
        serviceAccountLogin(req);/*from  w  w  w . j ava 2 s .  c o m*/
    } else if (reqUri.endsWith("/logout")) {
        logout(req);
    }

    // Don't load products if some error happened during login,refresh or logout
    if (req.getAttribute(ERROR) == null) {
        loadProducts(req);
    }

    req.getRequestDispatcher("/WEB-INF/page.jsp").forward(req, resp);
}

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

private void saveBase(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    User user = BlocklyPropSecurityUtils.getUserInfo();
    req.setAttribute("email", user.getEmail());
    req.setAttribute("screenname", user.getScreenname());
    String screenname = req.getParameter("screenname");
    if (Strings.isNullOrEmpty(screenname)) {
        req.setAttribute("base-error", "Missing fields");
        req.getRequestDispatcher("WEB-INF/servlet/profile/profile.jsp").forward(req, resp);
    } else {//from   w w w  . j av  a  2 s. co  m
        try {
            user = cloudSessionUserService.changeUserInfo(BlocklyPropSecurityUtils.getCurrentSessionUserId(),
                    screenname);
            if (user != null) {
                SecurityServiceImpl.getSessionData().setUser(user);
                userDao.updateScreenname(BlocklyPropSecurityUtils.getCurrentUserId(), user.getScreenname());
                req.setAttribute("base-success", "Info changed");
                req.setAttribute("screenname", user.getScreenname());
                req.getRequestDispatcher("WEB-INF/servlet/profile/profile.jsp").forward(req, resp);
            } else {
                req.setAttribute("base-error", "User info could not be changed");
                req.getRequestDispatcher("WEB-INF/servlet/profile/profile.jsp").forward(req, resp);
            }
        } catch (UnknownUserIdException uuie) {
            req.setAttribute("base-error", "Unknown user");
            req.getRequestDispatcher("WEB-INF/servlet/profile/profile.jsp").forward(req, resp);
        } catch (ScreennameUsedException sue) {
            req.setAttribute("base-error", "screenname-used");
            req.getRequestDispatcher("WEB-INF/servlet/profile/profile.jsp").forward(req, resp);
        } catch (ServerException se) {
            req.setAttribute("base-error", "Server error");
            req.getRequestDispatcher("WEB-INF/servlet/profile/profile.jsp").forward(req, resp);
        }
    }
}

From source file:org.deegree.test.gui.StressTestController.java

private void doStep1(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String capab = request.getParameter("capabilities");
    request.getSession().setAttribute("capab", capab);
    RequestDispatcher dispatcher = request.getRequestDispatcher("/wpvs_params.jsp");
    dispatcher.forward(request, response);

}

From source file:com.example.appengine.UrlFetchServlet.java

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

    // [START example]
    URL url = new URL("http://api.icndb.com/jokes/random");
    BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
    StringBuffer json = new StringBuffer();
    String line;/*w w  w  .j av  a2s .  c o m*/

    while ((line = reader.readLine()) != null) {
        json.append(line);
    }
    reader.close();
    // [END example]
    JSONObject jo = new JSONObject(json.toString());

    req.setAttribute("joke", jo.getJSONObject("value").getString("joke"));
    req.getRequestDispatcher("/main.jsp").forward(req, resp);
}

From source file:com.netcracker.financeapp.controller.agent.AgentServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    ArrayList<String> agentList = agentService.getAgentNames();
    request.setAttribute("agentList", agentList);

    String currentAgent = request.getParameter("agentListVal");
    if (currentAgent != null && currentAgent != "Select Agent") {

        Agent currAgent = agentService.getAgentByName(currentAgent);
        request.setAttribute("agentNumber", currAgent.getAccountNumber());
        request.setAttribute("agentName", currAgent.getName());
    }//  w  ww.  j a  va2 s  .c o m
    request.setAttribute("clearAgent", "Select Agent");
    request.getRequestDispatcher("agent/agentPage.jsp").forward(request, response);

}

From source file:com.pearson.pdn.demos.chainoflearning.CalendarServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {

    String email = (String) req.getSession().getAttribute("email");
    // save the email address to short-circuit getUserId later
    req.setAttribute("email", email);
    // Will only get here if someone is attempting to re-register.
    // The credential exist in storage, but the user might still have unauthorized the app
    // forget the user in storage
    CalendarUtility.forgetUserCredential(email, this.getCredential());
    // then call this servlet again to force auth again
    req.getRequestDispatcher("/oauth2").forward(req, res);
}

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

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    request.setCharacterEncoding("UTF-8");

    // check connection details
    if (strabonWrapper.getStrabon() == null) {
        RequestDispatcher dispatcher = request.getRequestDispatcher("/connection.jsp");

        // pass the current details of the connection
        request.setAttribute("username", strabonWrapper.getUsername());
        request.setAttribute("password", strabonWrapper.getPassword());
        request.setAttribute("dbname", strabonWrapper.getDatabaseName());
        request.setAttribute("hostname", strabonWrapper.getHostName());
        request.setAttribute("port", strabonWrapper.getPort());
        request.setAttribute("dbengine", strabonWrapper.getDBEngine());

        // pass the other parameters as well
        request.setAttribute("query", request.getParameter("query"));
        if (request.getParameter("format").equalsIgnoreCase("PIECHART")
                || request.getParameter("format").equalsIgnoreCase("AREACHART")
                || request.getParameter("format").equalsIgnoreCase("COLUMNCHART")) {
            request.setAttribute("format", "CHART");
        } else {//from w  ww.  ja v a  2  s.  c  o m
            request.setAttribute("format", request.getParameter("format"));
        }
        request.setAttribute("handle", request.getParameter("handle"));

        // forward the request
        dispatcher.forward(request, response);

    } else {

        if (Common.VIEW_TYPE.equals(request.getParameter(Common.VIEW))) {
            // HTML visual interface
            processVIEWRequest(request, response);

        } else {// invoked as a service
            processRequest(request, response);
        }
    }
}

From source file:com.cruz.sec.config.ItemBasedLogoutSuccessHandler.java

@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication a)
        throws IOException, ServletException {
    //Se enva a refrescar la ventana de todos los clientes para que cierre la sessin
    //        requestNodeJS.sendRequestWithUsernameAndMethod(a.getName(), "/session-close");
    try {/*from   w ww  .  ja v a2s .  c o  m*/
        System.out.println("-----------------------------SESIN CERRADA (" + a.getName()
                + ") -----------------------------");
    } catch (NullPointerException as) {
    }
    //        response.sendRedirect("login?out=1");
    request.setAttribute("ERRORSESSION", "Sesi&oacute;n cerrada exitosamente");
    request.getRequestDispatcher("/login").forward(request, response);
    //        response.sendRedirect(request.getContextPath() + "/login");
    //        RequestDispatcher dispatcher = request.getRequestDispatcher("/login");
    //        dispatcher.forward(request, response);
}