Java Code Examples for javax.servlet.http.HttpServletRequest#getRequestDispatcher()

The following examples show how to use javax.servlet.http.HttpServletRequest#getRequestDispatcher() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: redesocial   File: TiposAtividadesControle.java    License: MIT License 6 votes vote down vote up
private void editar(HttpServletRequest request, HttpServletResponse response) throws Exception{
    try {
        Integer id = Integer.parseInt(request.getParameter("id"));

        TiposAtividadesBO tiposAtividadesBO = new TiposAtividadesBO();
        TiposAtividades tiposAtividades = tiposAtividadesBO.selecionar(id);

        request.setAttribute("atividade", tiposAtividades);

        request.setAttribute("mensagem", "Registro selecionado com sucesso");
    } catch (Exception ex){
        request.setAttribute("erro", ex.getMessage());
    }

    RequestDispatcher rd = request.getRequestDispatcher("paginas/tiposAtividades.jsp");
    rd.forward(request, response);
}
 
Example 2
/**
 * Forward request to index page
 */
protected void forward(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {

    RequestDispatcher rd = request.getRequestDispatcher("index.jsp");
    rd.forward(request, response);
}
 
Example 3
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	javax.servlet.http.Cookie userCookie = new javax.servlet.http.Cookie("BenchmarkTest00970", "ECHOOO");
	userCookie.setMaxAge(60*3); //Store cookie for 3 minutes
	userCookie.setSecure(true);
	userCookie.setPath(request.getRequestURI());
	response.addCookie(userCookie);
	javax.servlet.RequestDispatcher rd = request.getRequestDispatcher("/cmdi-01/BenchmarkTest00970.html");
	rd.include(request, response);
}
 
Example 4
/**
 * Service provided by the fragment. This is the entry point of each
 * framgent. It generally includes a JSP page to render a certain part of
 * web viewer.
 * 
 * @param request
 *            incoming http request
 * @param response
 *            http response
 * @exception ServletException
 * @exception IOException
 */
public void service( HttpServletRequest request,
		HttpServletResponse response ) throws ServletException, IOException, BirtException
{
	doPreService( request, response );
	doService( request, response );
	String target = doPostService( request, response );

	if ( target != null && target.length( ) > 0 )
	{
		RequestDispatcher rd = request.getRequestDispatcher( target );
		rd.include( request, response );
	}
}
 
Example 5
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	javax.servlet.http.Cookie userCookie = new javax.servlet.http.Cookie("BenchmarkTest00992", "color");
	userCookie.setMaxAge(60*3); //Store cookie for 3 minutes
	userCookie.setSecure(true);
	userCookie.setPath(request.getRequestURI());
	response.addCookie(userCookie);
	javax.servlet.RequestDispatcher rd = request.getRequestDispatcher("/trustbound-00/BenchmarkTest00992.html");
	rd.include(request, response);
}
 
Example 6
Source Project: redesocial   File: TiposAtividadesControle.java    License: MIT License 5 votes vote down vote up
private void criarNovo(HttpServletRequest request, HttpServletResponse response) throws Exception{
    try {
        TiposAtividades tiposAtividades = new TiposAtividades();

        request.setAttribute("atividade", tiposAtividades);
    } catch (Exception ex){
        request.setAttribute("erro", ex.getMessage());
    }

    RequestDispatcher rd = request.getRequestDispatcher("paginas/tiposAtividades.jsp");
    rd.forward(request, response);
}
 
Example 7
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	javax.servlet.http.Cookie userCookie = new javax.servlet.http.Cookie("BenchmarkTest01869", "whatever");
	userCookie.setMaxAge(60*3); //Store cookie for 3 minutes
	userCookie.setSecure(true);
	userCookie.setPath(request.getRequestURI());
	response.addCookie(userCookie);
	javax.servlet.RequestDispatcher rd = request.getRequestDispatcher("/weakrand-04/BenchmarkTest01869.html");
	rd.include(request, response);
}
 
Example 8
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	javax.servlet.http.Cookie userCookie = new javax.servlet.http.Cookie("BenchmarkTest00004", "color");
	userCookie.setMaxAge(60*3); //Store cookie for 3 minutes
	userCookie.setSecure(true);
	userCookie.setPath(request.getRequestURI());
	response.addCookie(userCookie);
	javax.servlet.RequestDispatcher rd = request.getRequestDispatcher("/trustbound-00/BenchmarkTest00004.html");
	rd.include(request, response);
}
 
Example 9
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	javax.servlet.http.Cookie userCookie = new javax.servlet.http.Cookie("BenchmarkTest01866", "whatever");
	userCookie.setMaxAge(60*3); //Store cookie for 3 minutes
	userCookie.setSecure(true);
	userCookie.setPath(request.getRequestURI());
	response.addCookie(userCookie);
	javax.servlet.RequestDispatcher rd = request.getRequestDispatcher("/weakrand-04/BenchmarkTest01866.html");
	rd.include(request, response);
}
 
Example 10
Source Project: gradle-in-action-source   File: ToDoServlet.java    License: MIT License 5 votes vote down vote up
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String servletPath = request.getServletPath();
    String view = processRequest(servletPath, request);
    RequestDispatcher dispatcher = request.getRequestDispatcher(view);
    dispatcher.forward(request, response);
}
 
Example 11
private void loadErrorPage(final HttpServletRequest request, final HttpServletResponse response) {
    final RequestDispatcher requestDispatcher = request.getRequestDispatcher("/no-conversation-state.jsp");
    try {
        requestDispatcher.forward(request, response);
    } catch (final Exception e) {
        logger.error("Error rendering the empty conversation state (shib-cas-authn3) error view.");
        response.resetBuffer();
        response.setStatus(404);
    }
}
 
Example 12
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	javax.servlet.http.Cookie userCookie = new javax.servlet.http.Cookie("BenchmarkTest01874", "color");
	userCookie.setMaxAge(60*3); //Store cookie for 3 minutes
	userCookie.setSecure(true);
	userCookie.setPath(request.getRequestURI());
	response.addCookie(userCookie);
	javax.servlet.RequestDispatcher rd = request.getRequestDispatcher("/trustbound-01/BenchmarkTest01874.html");
	rd.include(request, response);
}
 
Example 13
Source Project: gradle-in-action-source   File: ToDoServlet.java    License: MIT License 5 votes vote down vote up
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String servletPath = request.getServletPath();
    String view = processRequest(servletPath, request);
    RequestDispatcher dispatcher = request.getRequestDispatcher(view);
    dispatcher.forward(request, response);
}
 
Example 14
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	javax.servlet.http.Cookie userCookie = new javax.servlet.http.Cookie("BenchmarkTest01876", "my_userid");
	userCookie.setMaxAge(60*3); //Store cookie for 3 minutes
	userCookie.setSecure(true);
	userCookie.setPath(request.getRequestURI());
	response.addCookie(userCookie);
	javax.servlet.RequestDispatcher rd = request.getRequestDispatcher("/trustbound-01/BenchmarkTest01876.html");
	rd.include(request, response);
}
 
Example 15
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	javax.servlet.http.Cookie userCookie = new javax.servlet.http.Cookie("BenchmarkTest00076", "someSecret");
	userCookie.setMaxAge(60*3); //Store cookie for 3 minutes
	userCookie.setSecure(true);
	userCookie.setPath(request.getRequestURI());
	response.addCookie(userCookie);
	javax.servlet.RequestDispatcher rd = request.getRequestDispatcher("/hash-00/BenchmarkTest00076.html");
	rd.include(request, response);
}
 
Example 16
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	javax.servlet.http.Cookie userCookie = new javax.servlet.http.Cookie("BenchmarkTest01837", "FileName");
	userCookie.setMaxAge(60*3); //Store cookie for 3 minutes
	userCookie.setSecure(true);
	userCookie.setPath(request.getRequestURI());
	response.addCookie(userCookie);
	javax.servlet.RequestDispatcher rd = request.getRequestDispatcher("/pathtraver-02/BenchmarkTest01837.html");
	rd.include(request, response);
}
 
Example 17
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	javax.servlet.http.Cookie userCookie = new javax.servlet.http.Cookie("BenchmarkTest00967", "someSecret");
	userCookie.setMaxAge(60*3); //Store cookie for 3 minutes
	userCookie.setSecure(true);
	userCookie.setPath(request.getRequestURI());
	response.addCookie(userCookie);
	javax.servlet.RequestDispatcher rd = request.getRequestDispatcher("/hash-01/BenchmarkTest00967.html");
	rd.include(request, response);
}
 
Example 18
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	javax.servlet.http.Cookie userCookie = new javax.servlet.http.Cookie("BenchmarkTest00063", "FileName");
	userCookie.setMaxAge(60*3); //Store cookie for 3 minutes
	userCookie.setSecure(true);
	userCookie.setPath(request.getRequestURI());
	response.addCookie(userCookie);
	javax.servlet.RequestDispatcher rd = request.getRequestDispatcher("/pathtraver-00/BenchmarkTest00063.html");
	rd.include(request, response);
}
 
Example 19
/**
     * Strip off the <code>/LBS</code> prefix from the requestURI and forward
     * the request to the servlet at the resulting requestURI. This forwarding
     * effectively disables the LBS but still allows requests which target the
     * LBS to succeed against the webapp on the same host.
     * <p>
     * Note: If the deployment is does not support HA replication (e.g., either
     * not HA or HA with replicationFactor:=1), then we still want to be able to
     * forward to the local service.
     * 
     * @param request
     *            The request.
     * @param response
     *            The response.
     * 
     * @throws IOException
     * @throws ServletException
     * 
     * @see <a href="http://trac.blazegraph.com/ticket/965" > Cannot run queries in
     *      LBS mode with HA1 setup </a>
     */
    public void forwardToLocalService(//
            final boolean isLeaderRequest,//
            final HttpServletRequest request, //
            final HttpServletResponse response//
    ) throws IOException {

        final String path = request.getRequestURI();

        // The prefix for the LBS servlet.
        final String prefix = (String) request.getServletContext()
                .getAttribute(BigdataServlet.ATTRIBUTE_LBS_PREFIX);

        if (prefix == null) {
            // LBS is not running / destroyed.
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            return;
        }

        if (!path.startsWith(prefix)) {
            // Request should not have reached the LBS.
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            return;
        }

        // the full LBS prefix (includes /leader or /read).
        final String full_prefix = getFullPrefix(isLeaderRequest, prefix);

        // what remains after we strip off the full LBS prefix.
        final String rest = path.substring(full_prefix.length());

        // build up path w/o LBS prefix.
        final StringBuilder uri = new StringBuilder();
        
        if (!rest.startsWith("/")) {
            /*
             * The new path must start with '/' and is relative to this
             * ServletContext.
             */
            uri.append("/");
        }

        // append the remainder of the original requestURI
        uri.append(rest);
        
//        // append the query parameters (if any).
//        final String query = request.getQueryString();
//        if (query != null)
//            uri.append("?").append(query);

        // The new path.
        final String newPath = uri.toString();
        
        /*
         * Forward the request to this servlet container now that we have
         * stripped off the prefix for the LBS.
         */

        // Get dispatched for the new requestURL path.
        final RequestDispatcher requestDispatcher = request
                .getRequestDispatcher(newPath);

        try {

            nforward.increment();
            
            if (log.isInfoEnabled())
                log.info("forward: " + path + " => " + newPath);

            // forward to a local servlet.
            requestDispatcher.forward(request, response);
            
        } catch (ServletException e) {
            
            throw new IOException("Could not forward: requestURL=" + path, e);
            
        }

    }
 
Example 20
/**
 * Obtain the RequestDispatcher to use for the forward/include.
 * <p>The default implementation simply calls
 * {@link HttpServletRequest#getRequestDispatcher(String)}.
 * Can be overridden in subclasses.
 * @param request current HTTP request
 * @param path the target URL (as returned from {@link #prepareForRendering})
 * @return a corresponding RequestDispatcher
 */
@Nullable
protected RequestDispatcher getRequestDispatcher(HttpServletRequest request, String path) {
	return request.getRequestDispatcher(path);
}