Package javax.servlet

Examples of javax.servlet.RequestDispatcher


        throws ServletException {
       
        String theServletPath = dispatcherServletPath == null ? "/" : dispatcherServletPath;
       
        ServletContext sc = super.getServletContext();
        RequestDispatcher rd = dispatcherServletName != null
            ? sc.getNamedDispatcher(dispatcherServletName)
            : sc.getRequestDispatcher(theServletPath + pathInfo);
        if (rd == null) {
            throw new ServletException("No RequestDispatcher can be created for path " + pathInfo);
        }
        try {
            HttpServletRequestFilter servletRequest =
                new HttpServletRequestFilter(request, pathInfo, theServletPath);
            rd.forward(servletRequest, response);
        } catch (Throwable ex) {
            throw new ServletException("RequestDispatcher for path " + pathInfo + " has failed");
        }  
    }
View Full Code Here


    @Override
    protected void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
        bzb = new BooksZenBooks( "en", dbConfigResource ); // @TODO language should be a request param
        String action = RequestHelper.getString( "action", request );
        String forwardUrl;
        RequestDispatcher dispatcher;
        HashMap<String, String> formErrors;
        User user;
       
        /* Load necessary lexicons */
        bzb.getLexicon().load( "global" );
        bzb.getLexicon().load( "register" );
        bzb.getLexicon().load( "subject" );

        /* Already logged in? */
        if( bzb.getAuthenticatedUser( request ) != null ) {
            forwardUrl = "/index";
        }
        /* Handle registration request */
        else if( action.equals( "register" ) ) {
            formErrors = checkRegistration( request );

            /* No form errors, create the user and display validation page */
            if( formErrors.isEmpty() ) {
                user = createUser( request );

                sendValidationEmail( user );

                // @TODO remove below after email is working
                request.setAttribute( "confirmCode", user.getValidationCode() );
               
                forwardUrl = jspPath + "validationCode.jsp";
            }
            /* Show form errors */
            else {
                forwardUrl = jspPath + "register.jsp";

                request.setAttribute( "formErrors", formErrors );
                request.setAttribute( "countries", getCountries() );
            }
        }
        /* Confirming an account */
        else if( action.equals( "confirm" ) ) {
            /* No email entered - display the form */
            if( request.getParameter( "email" ) == null ) {
                forwardUrl = jspPath + "validationCode.jsp";

                request.setAttribute( "pageTitle", bzb.getLexicon().get( "confirmAccount" ) );
            }
            /* Code and email match - update user and display success */
            else if( ( user = checkValidationCode( request ) ) != null ) {
                forwardUrl = jspPath + "registerSuccess.jsp";

                user.setValidated( true );
                user.save();

                request.setAttribute( "pageTitle", bzb.getLexicon().get( "registerSuccess" ) );
            }
            /* Show validation page with errors */
            else {
                forwardUrl = jspPath + "validationCode.jsp";

                request.setAttribute( "pageTitle", bzb.getLexicon().get( "confirmAccount" ) );
                request.setAttribute( "codeInvalid", true );
            }
        }
        /* Display the registration form */
        else {
            forwardUrl = jspPath + "register.jsp";

            request.setAttribute( "pageTitle", bzb.getLexicon().get( "registerAccount" ) );
            request.setAttribute( "countries", getCountries() );
        }

        /* Make lexicons and config settings available to JSP */
        request.setAttribute( "config", bzb.getConfig().getSettings() );
        request.setAttribute( "lexicon", bzb.getLexicon().getLexicons() );
        request.setAttribute( "language", bzb.getLexicon().getLanguage() );
        request.setAttribute( "subjects", bzb.getSubjects() );
       
        /* Set up forward and display JSP */
        dispatcher = getServletContext().getRequestDispatcher( forwardUrl );

        dispatcher.forward( request, response );
    }
View Full Code Here

    protected void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
        bzb = new BooksZenBooks( "en", dbConfigResource ); // @TODO language should be a request param
        String forwardUrl;
        String pageTitle;
        String action = RequestHelper.getString( "action", request );
        RequestDispatcher dispatcher;
        HashMap<String, String> formErrors;
        User authUser = bzb.getAuthenticatedUser( request );

        /* Load necessary lexicons */
        bzb.getLexicon().load( "global" );
        bzb.getLexicon().load( "subject" );
        bzb.getLexicon().load( "register" );
        bzb.getLexicon().load( "ucp" );

        if( authUser == null ) {
            bzb.getLexicon().load( "error" );
            bzb.getLexicon().load( "register" );

            forwardUrl = jspPath + "401.jsp";
            pageTitle = bzb.getLexicon().get( "unauthorized" );
        }
        else if( action.equals( "save" ) ) {
            formErrors = checkForm( request );

            if( !formErrors.isEmpty() ) {
                bzb.getLexicon().load( "register" );

                forwardUrl = jspPath + "editProfile.jsp";
                pageTitle = bzb.getLexicon().get( "editProfile" );

                request.setAttribute( "countries", getCountries() );
                request.setAttribute( "formErrors", formErrors );
            }
            else {
                pageTitle = bzb.getLexicon().get( "profileUpdated" );
                forwardUrl = jspPath + "editProfileSuccess.jsp";
               
                request.setAttribute( "user", saveUser( request ) );
            }
        }
        else {
            bzb.getLexicon().load( "register" );

            forwardUrl = jspPath + "editProfile.jsp";
            pageTitle = bzb.getLexicon().get( "editProfile" );

            request.setAttribute( "countries", getCountries() );
            request.setAttribute( "user", authUser );
        }

        /* Make lexicons and config settings available to JSP */
        request.setAttribute( "config", bzb.getConfig().getSettings() );
        request.setAttribute( "lexicon", bzb.getLexicon().getLexicons() );
        request.setAttribute( "language", bzb.getLexicon().getLanguage() );
        request.setAttribute( "subjects", bzb.getSubjects() );
        request.setAttribute( "pageTitle", pageTitle );

        /* Set up forward and display JSP */
        dispatcher = getServletContext().getRequestDispatcher( forwardUrl );

        dispatcher.forward( request, response );
    }
View Full Code Here

    protected void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
        bzb = new BooksZenBooks( "en", dbConfigResource ); // @TODO language should be a request param
        String forwardUrl;
        String pageTitle;
        String action = RequestHelper.getString( "action", request );
        RequestDispatcher dispatcher;

        /* Load necessary lexicons */
        bzb.getLexicon().load( "global" );
        bzb.getLexicon().load( "subject" );
        bzb.getLexicon().load( "ucp" );

        if( bzb.getAuthenticatedUser( request ) == null ) {
            bzb.getLexicon().load( "error" );
            bzb.getLexicon().load( "register" );

            forwardUrl = jspPath + "401.jsp";
            pageTitle = bzb.getLexicon().get( "unauthorized" );
        }
        else if( action.equals( "listings" ) ) {
            bzb.getLexicon().load( "book" );
            bzb.getLexicon().load( "listing" );
            bzb.getLexicon().load( "search" );

            forwardUrl = jspPath + "myListings.jsp";
            pageTitle = bzb.getLexicon().get( "myListings" );

            request.setAttribute( "listings", getUserListings( request ) );
        }
        else if( action.equals( "profile" ) ) {
            forwardUrl = "/editProfile";
            pageTitle = bzb.getLexicon().get( "editProfile" );
        }
        else {
            forwardUrl = jspPath + "myControls.jsp";
            pageTitle = bzb.getLexicon().get( "myControls" );
        }

       

        /* Make lexicons and config settings available to JSP */
        request.setAttribute( "config", bzb.getConfig().getSettings() );
        request.setAttribute( "lexicon", bzb.getLexicon().getLexicons() );
        request.setAttribute( "language", bzb.getLexicon().getLanguage() );
        request.setAttribute( "subjects", bzb.getSubjects() );
        request.setAttribute( "pageTitle", pageTitle );

        /* Set up forward and display JSP */
        dispatcher = getServletContext().getRequestDispatcher( forwardUrl );

        dispatcher.forward( request, response );
    }
View Full Code Here

     */
    @Override
    protected void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
        bzb = new BooksZenBooks( "en", dbConfigResource ); // @TODO language should be a request param
        String forwardUrl = jspPath + "home";
        RequestDispatcher dispatcher;
        User user = bzb.getAuthenticatedUser( request );

        /* Load necessary lexicons */
        bzb.getLexicon().load( "global" );
        bzb.getLexicon().load( "checkout" );
        bzb.getLexicon().load( "subject" );

        /* Make lexicons and config settings available to JSP */
        request.setAttribute( "config", bzb.getConfig().getSettings() );
        request.setAttribute( "lexicon", bzb.getLexicon().getLexicons() );
        request.setAttribute( "language", bzb.getLexicon().getLanguage() );
        request.setAttribute( "subjects", bzb.getSubjects() );
        request.getSession().setAttribute( "authUser", user );

        /* Set up forward and display JSP */
        dispatcher = getServletContext().getRequestDispatcher( forwardUrl );

        dispatcher.forward( request, response );
    }
View Full Code Here

    protected void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
        bzb = new BooksZenBooks( "en", dbConfigResource ); // @TODO language should be a request param
        String forwardUrl;
        String pageTitle;
        int step = RequestHelper.getInt( "step", request );
        RequestDispatcher dispatcher;
        HashMap<String, String> formErrors = new HashMap<String, String>();
        BookListing listing = ( BookListing ) request.getSession().getAttribute( "userListing" );
        Book book;

        /* Load necessary lexicons */
        bzb.getLexicon().load( "global" );
        bzb.getLexicon().load( "subject" );
        bzb.getLexicon().load( "book" );
        bzb.getLexicon().load( "listing" );

        pageTitle = bzb.getLexicon().get( "addListing" );

        /* Make sure user is logged in */
        if( bzb.getAuthenticatedUser( request ) == null ) {
            bzb.getLexicon().load( "error" );

            forwardUrl = jspPath + "401.jsp";
            pageTitle = bzb.getLexicon().get( "unauthorized" );
        }
        /* User has submitted the initial ISBN form */
        else if( step == 2 ) {
            /* Invalid ISBN */
            if( !isValidISBN( RequestHelper.getString( "isbn", request ) ) ) {
                forwardUrl = jspPath + "newListingStep1.jsp";

                formErrors.put( "isbn", bzb.getLexicon().get( "invalidField", new String[][]{ { "field", bzb.getLexicon().get( "isbn" ) } } ) );
            }
            else {
                forwardUrl = jspPath + "newListingStep2.jsp";

                request.setAttribute( "languages", getLanguages() );
                /* Add book data to request, if it exists in the DB */
                request.setAttribute( "book", getBook( RequestHelper.getString( "isbn", request ) ) );
            }
        }
        /* User has submitted the book form */
        else if( step == 3 ) {
            /* Existing book? */
            if( RequestHelper.getString( "newBook", request ).equals( "false" ) ) {
                /* Invalid ISBN */
                if( !isValidISBN( RequestHelper.getString( "isbn", request ) ) ) {
                    forwardUrl = jspPath + "newListingStep1.jsp";

                    formErrors.put( "isbn", bzb.getLexicon().get( "invalidField", new String[][]{ { "field", bzb.getLexicon().get( "isbn" ) } } ) );
                }
                else {
                    /* Check to see if book exists in the DB */
                    if( ( book = getBook( RequestHelper.getString( "isbn", request ) ) ) != null ) {
                        forwardUrl = jspPath + "newListingStep3.jsp";

                        /* Create empty listing object for later */
                        if( listing == null ) {
                            listing = new BookListing();
                        }

                        listing.setBook( book );

                        /* Put listing object in SESSION object */
                        request.getSession().setAttribute( "userListing", listing );
                        request.setAttribute( "conditions", getConditions() );
                    }
                    else {
                        forwardUrl = jspPath + "newListingStep1.jsp";

                        formErrors.put( "isbn", bzb.getLexicon().get( "invalidField", new String[][]{ { "field", bzb.getLexicon().get( "isbn" ) } } ) );
                    }
                }
            }
            /* New book being submitted */
            else {
                formErrors = checkBookForm( request);

                /* Has errors - display book form again */
                if( !formErrors.isEmpty() ) {
                    forwardUrl = jspPath + "newListingStep2.jsp";

                    request.setAttribute( "languages", getLanguages() );
                }
                /* No errors - display listing form */
                else {
                    forwardUrl = jspPath + "newListingStep3.jsp";

                    if( listing == null ) {
                        listing = new BookListing();
                    }

                    /* Add listing to SESSION */
                    listing.setBook( getBookFromInput( request ) );
                    request.getSession().setAttribute( "userListing", listing );
                    request.setAttribute( "conditions", getConditions() );
                }
            }
        }
        /* Submitted the final listing form */
        else if( step == 4 ) {
            /* Hey, you can't skip to the end just yet! */
            if( listing == null ) {
                forwardUrl = jspPath + "newListingStep1.jsp";

                formErrors.put( "page", bzb.getLexicon().get( "timeOut" ) );
            }
            /* Make sure form is valid */
            else {
                formErrors = checkListingForm( request );

                /* Invalid - display listing form again */
                if( !formErrors.isEmpty() ) {
                    forwardUrl = jspPath + "newListingStep3.jsp";

                    request.setAttribute( "conditions", getConditions() );
                }
                /* Create listing and display success page */
                else {
                    saveListing( listing, request );

                    forwardUrl = jspPath + "newListingDone.jsp";
                }
            }
        }
        /* Display initial ISBN form */
        else {
            forwardUrl = jspPath + "newListingStep1.jsp";
        }

        /* Make lexicons and config settings available to JSP */
        request.setAttribute( "config", bzb.getConfig().getSettings() );
        request.setAttribute( "lexicon", bzb.getLexicon().getLexicons() );
        request.setAttribute( "language", bzb.getLexicon().getLanguage() );
        request.setAttribute( "subjects", bzb.getSubjects() );
        request.setAttribute( "pageTitle", pageTitle );
        request.setAttribute( "formErrors", formErrors );

        /* Set up forward and display JSP */
        dispatcher = getServletContext().getRequestDispatcher( forwardUrl );

        dispatcher.forward( request, response );
    }
View Full Code Here

    @Override
    protected void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
        bzb = new BooksZenBooks( "en", dbConfigResource ); // @TODO language should be a request param
        String action = RequestHelper.getString( "action", request );
        String forwardUrl;
        RequestDispatcher dispatcher;
        User user;

        /* Load necessary lexicons */
        bzb.getLexicon().load( "global" );
        bzb.getLexicon().load( "register" );
        bzb.getLexicon().load( "subject" );

        /* Handle logout request */
        if( action.equals( "logout" ) ) {
            forwardUrl = jspPath + "/loggedOut.jsp";

            endSession( request, response );
        }
        /* Handle login request */
        else if( action.equals( "login" ) ) {
            /* Already logged in? */
            if( bzb.getAuthenticatedUser( request ) != null ) {
                forwardUrl = "/home";
            }
            else {
                /* Verify email and password */
                user = checkCredentials( request );

                /* No matching user */
                if( user == null ) {
                    forwardUrl = jspPath + "login.jsp";

                    request.setAttribute( "pageTitle", bzb.getLexicon().get( "logIn" ) );
                    request.setAttribute( "formError", bzb.getLexicon().get( "invalidLogin" ) );
                }
                /* Not validated yet */
                else if( !user.isValidated() ) {
                    forwardUrl = jspPath + "login.jsp";

                    request.setAttribute( "pageTitle", bzb.getLexicon().get( "logIn" ) );
                    request.setAttribute( "formError", bzb.getLexicon().get( "notValidated" ) );
                }
                /* User matched AND is validated */
                else {
                    forwardUrl = "/home";

                    startSession( user, request, response );
                }
            }
        }
        /* Requesting the initial login page */
        else {
            if( bzb.getAuthenticatedUser( request ) != null ) {
                forwardUrl = "/home";
            }
            else {
                forwardUrl = jspPath + "login.jsp";

                request.setAttribute( "pageTitle", bzb.getLexicon().get( "logIn" ) );
            }
        }

        /* Make lexicons and config settings available to JSP */
        request.setAttribute( "config", bzb.getConfig().getSettings() );
        request.setAttribute( "lexicon", bzb.getLexicon().getLexicons() );
        request.setAttribute( "language", bzb.getLexicon().getLanguage() );
        request.setAttribute( "subjects", bzb.getSubjects() );

        /* Set up forward and display JSP */
        dispatcher = getServletContext().getRequestDispatcher( forwardUrl );

        dispatcher.forward( request, response );
    }
View Full Code Here

        String forwardUrl;
        String pageTitle;
        String message = null;
        boolean isError = false;
        String action = RequestHelper.getString( "action", request );
        RequestDispatcher dispatcher;

        bzb.getLexicon().load( "global" );
        bzb.getLexicon().load( "subject" );
        bzb.getLexicon().load( "cart" );
        bzb.getLexicon().load( "search" );
        bzb.getLexicon().load( "book" );
       
        pageTitle = bzb.getLexicon().get( "cart" );
        forwardUrl = jspPath + "shoppingCart.jsp";

        if( bzb.getAuthenticatedUser( request ) == null ) {
            bzb.getLexicon().load( "error" );
            bzb.getLexicon().load( "register" );

            forwardUrl = jspPath + "401.jsp";
            pageTitle = bzb.getLexicon().get( "unauthorized" );
        }
        else if( action.equals( "add" ) ) {
            if( isValidListing( request ) && addToCart( request ) ) {
                message = bzb.getLexicon().get( "cartAddSuccess" );
            }
            else {
                message = bzb.getLexicon().get( "cartAddError" );
                isError = true;
            }
        }
        else if( action.equals( "remove" ) ) {
            if( removeFromCart( request ) ) {
                message = bzb.getLexicon().get( "cartRemoveSuccess" );
            }
            else {
                message = bzb.getLexicon().get( "cartRemoveError" );
                isError = true;
            }
        }

        /* Make lexicons and config settings available to JSP */
        request.setAttribute( "config", bzb.getConfig().getSettings() );
        request.setAttribute( "lexicon", bzb.getLexicon().getLexicons() );
        request.setAttribute( "language", bzb.getLexicon().getLanguage() );
        request.setAttribute( "subjects", bzb.getSubjects() );
        request.setAttribute( "pageTitle", pageTitle );
        request.setAttribute( "message", message );
        request.setAttribute( "isError", isError );
        request.setAttribute( "listings", getListings( request ) );

        /* Set up forward and display JSP */
        dispatcher = getServletContext().getRequestDispatcher( forwardUrl );

        dispatcher.forward( request, response );
    }
View Full Code Here

    @Override
    protected void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
        bzb = new BooksZenBooks( "en", dbConfigResource ); // @TODO language should be a request param
        String action = RequestHelper.getString( "action", request );
        String forwardUrl;
        RequestDispatcher dispatcher;
        ArrayList<String> searchParams;

        /* Load necessary lexicons */
        bzb.getLexicon().load( "global" );
        bzb.getLexicon().load( "search" );
        bzb.getLexicon().load( "book" );
        bzb.getLexicon().load( "subject" );

        searchParams = buildSearchParams( request );

        if( action.equals( "advancedSearch" ) ) {
            forwardUrl = jspPath + "advancedSearch.jsp";

            request.setAttribute( "conditions", getConditions() );
            request.setAttribute( "languages", getLanguages() );
            request.setAttribute( "sortFields", getSortFields() );
            request.setAttribute( "pageTitle", bzb.getLexicon().get( "advancedSearch" ) );
        }
        else {
            forwardUrl = jspPath + "searchResults.jsp";

            request.setAttribute( "pageTitle", bzb.getLexicon().get( "searchResults" ) );
            request.setAttribute( "listings", getSearchResults( searchParams ) );
        }

        /* Make lexicons and config settings available to JSP */
        request.setAttribute( "config", bzb.getConfig().getSettings() );
        request.setAttribute( "lexicon", bzb.getLexicon().getLexicons() );
        request.setAttribute( "language", bzb.getLexicon().getLanguage() );
        request.setAttribute( "subjects", bzb.getSubjects() );

        /* Set up forward and display JSP */
        dispatcher = getServletContext().getRequestDispatcher( forwardUrl );

        dispatcher.forward( request, response );
    }
View Full Code Here

    protected void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
        bzb = new BooksZenBooks( "en", dbConfigResource ); // @TODO language should be a request param
        String forwardUrl;
        String pageTitle;
        String action = RequestHelper.getString( "action", request );
        RequestDispatcher dispatcher;
        HashMap<String, String> formErrors;
        BookListing listing = getListing( RequestHelper.getInt( "listId", request ) );
        User authUser = bzb.getAuthenticatedUser( request );

        /* Load necessary lexicons */
        bzb.getLexicon().load( "global" );
        bzb.getLexicon().load( "subject" );
        bzb.getLexicon().load( "book" );
        bzb.getLexicon().load( "listing" );

        if( listing == null ) {
            bzb.getLexicon().load( "error" );

            forwardUrl = jspPath + "404.jsp";
            pageTitle = bzb.getLexicon().get( "listingNotFound" );

            request.setAttribute( "customError", bzb.getLexicon().get( "listingNotFoundDesc" ) );
        }
        else if( authUser == null || authUser.getUserId() != listing.getUserId() ) {
            bzb.getLexicon().load( "error" );
            bzb.getLexicon().load( "register" );

            forwardUrl = jspPath + "401.jsp";
            pageTitle = bzb.getLexicon().get( "unauthorized" );

            request.setAttribute( "customError", bzb.getLexicon().get( "notUserListing" ) );
        }
        else if( action.equals( "save" ) ) {
            formErrors = checkListingForm( request );

            listing.setCondition( RequestHelper.getString( "condition", request ) );
            listing.setPrice( RequestHelper.getDouble( "price", request ) );
            listing.setComment( RequestHelper.getString( "comment", request ) );
            listing.setActive( RequestHelper.getBoolean( "active", request ) );

            if( !formErrors.isEmpty() ) {
                forwardUrl = jspPath + "editListingForm.jsp";
                pageTitle = bzb.getLexicon().get( "editListing" );
               
                request.setAttribute( "listing", listing );
                request.setAttribute( "formErrors", formErrors );
                request.setAttribute( "conditions", getConditions() );
            }
            else {
                updateListing( listing, request );

                forwardUrl = jspPath + "editListingSuccess.jsp";
                pageTitle = bzb.getLexicon().get( "listingUpdated" );
            }
        }
        else {           
            forwardUrl = jspPath + "editListingForm.jsp";
            pageTitle = bzb.getLexicon().get( "editListing" );

            request.setAttribute( "listing", listing );
            request.setAttribute( "conditions", getConditions() );
        }

        /* Make lexicons and config settings available to JSP */
        request.setAttribute( "config", bzb.getConfig().getSettings() );
        request.setAttribute( "lexicon", bzb.getLexicon().getLexicons() );
        request.setAttribute( "language", bzb.getLexicon().getLanguage() );
        request.setAttribute( "subjects", bzb.getSubjects() );
        request.setAttribute( "pageTitle", pageTitle );

        /* Set up forward and display JSP */
        dispatcher = getServletContext().getRequestDispatcher( forwardUrl );

        dispatcher.forward( request, response );
    }
View Full Code Here

TOP

Related Classes of javax.servlet.RequestDispatcher

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.