Jump to content

Redirects With Dispatchers


Recommended Posts

Hey Guys, I'm designing an online store. I'm using struts to maintain an MVC-type architecture, but I do not think that should have too much an impact on my issues here. So, when you're shoping online, and you click 'Add to Cart' or whatever, and alot of times it brings you to your cart page and shows the stuff. Well, I made a cart widget that sits in the corner, so that, at least until checkout, you don't need to go to a seperate cart page. So the problem here is that when you click add-to-cart, I want that exact same page to reload, with whatever request paramaters it had before (if there was a search, maintain the searched state, or the page number of the results you were viewing, etc.). So here's some code:

                log.append( LogDate.formatDate(Calendar.getInstance()) + " -- Entered AddToCart\n" );                log.flush();                            long id = Long.parseLong( request.getParameter("prodID") );                                log.append( "\tProductID to Add: " + id + "\n" );                log.append( LogDate.formatDate(Calendar.getInstance()) + " -- Adding Product to Cart (action class)\n" );                log.flush();                                addProduct(id, cart, quantity, log);                                log.append( LogDate.formatDate(Calendar.getInstance()) + " -- Added Product to Cart (action class)\n" );                log.append( LogDate.formatDate(Calendar.getInstance()) + " -- Putting Cart in Session Object\n" );                log.flush();                                session.setAttribute("cart", cart);                session.setAttribute("quantity", quantity);                                log.append( LogDate.formatDate(Calendar.getInstance()) + " -- Cart put in Session Object\n" );                log.flush();                                log.append(LogDate.formatDate(Calendar.getInstance()) + " -- Writing Session Data (addtocart)...\n");                writeSessionData(cart, quantity, log, session);                log.append(LogDate.formatDate(Calendar.getInstance()) + " -- ...Session Data Written! (addtocart)\n");                                String queryString = request.getParameter("sendBackURL");                log.append( "\tQUERYSTRING (sendBackURL) from REQUEST: " + queryString + "\n" );                                if ( queryString != null )                {                    RequestDispatcher dispatcher = request.getRequestDispatcher(ShoppingConstants.homePath + "?" + queryString);                    log.append( "\tdispatcher.toString(): " + dispatcher.toString() + "\n" );                                        if (dispatcher != null)                    {dispatcher.forward(request, response);}                }                                forwardString = "add";

homePath = "shop/shop.do" - it's in a config file of sortsSo, you can see that I do grab the query string successfully, and it gets to the action class, but if you try to use that action, and it tries to dispatch the request to that site, I get an error: The requested resource (Invalid path was requested) is not available. And that's going to be because it maintains both URLs. Here's where it tries to go when the link is clicked:dispatch-eCommerce/shop/shop.do?action=addtocart&prodID=2006&sendBackURL=action=search&d-4929346-p=2&searchWord=ttThe bold is what I want the query string to be - that's it. Once it adds the product to the cart, I don't need to know the 'addtocart' action or the product ID. But, there it is. Is there a way I can modify the code so that when it dispatches, it sends the request to this address?:dispatch-eCommerce/shop/shop.do?action=search&d-4929346-p=2&searchWord=tt

Edited by awitt
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...