• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

need guidance on this exercise

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am working on this exercise which requires me to do the following:

-Create a new servlet called RemoveItemsFromCart.java.

-Get it working with ReviewShoppingCart.java and AddToShoppingCart.java.

-You will need to edit ReviewShoppingCart.java to add another button that calls RemoveItemsFromCart.java


I have created the new servlet and the three are pasted below.

But my problem is that when I click the Remove button nothing happens.

I would be really thankful if someone guides me on this exercise. Causing me a lot of headache. Please advise if I am following an incorrect approach and if so what I should do.

Thanks in advance.
Ricky






[ April 10, 2007: Message edited by: Ricky James ]
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aren't you allowed to use JSP ? Those servlets are a pain to read with all those html tags. Basically, you do some logic in your servlet and redirect to a JSP file to display the results. If you can use JSP in your assignment, clean those servlets first
 
Ricky James
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Satou kurinosuke:
Aren't you allowed to use JSP ? Those servlets are a pain to read with all those html tags. Basically, you do some logic in your servlet and redirect to a JSP file to display the results. If you can use JSP in your assignment, clean those servlets first



I am not allowed to use JSPs. But I think if you just copy and paste this code in your IDE, it becomes fairly clear and legible. I have the logic wrong somewhere but can't figure out what is wrong.

For example, I think that the 2 forms on 1 page are returning the hidden stuff.

Thanks
Ricky
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am not allowed to use JSPs.


That's a pity It's very hard to understand what's going on

I can see that you have before the second form. You should remove both body and html closing tags.
 
Ricky James
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Satou kurinosuke:

That's a pity It's very hard to understand what's going on

I can see that you have before the second form. You should remove both body and html closing tags.



Thanks for the reply Satou.

I did what you suggested but the problem still exists.

I have a feeling that since I have a checkbox named items and also a hidden value named items. Now when I want to remove the items, only the hidden values gets transmitted, not the checkbox since there are in a different form. So there is no way of knowing which items have been unchecked.

But I am still confused as to what I should do.

Any suggestions?
Thanks
Ricky
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your items checkboxes are not in a form, so they won't be sent.
What I suggest you to do is :
1. Make only one form
2. In the form, put the checkboxes, but no hidden items. You don't need them, because you only want the values of the checked items.
3. In the form, put the two submit buttons.
4. Use javascript's onClick() event to dynamically change the form's action
-> On pressing "Add more items", you set it to "AddToShoppingCart"
-> On pressing "Remove items", you set it to "RemoveItemsFromCart"

I'm surprised that you can't use JSP for this, as it's going to be a pain in the **** to output some Javascript from your servlet.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic