aspose file tools*
The moose likes Servlets and the fly likes need guidance on this exercise Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "need guidance on this exercise" Watch "need guidance on this exercise" New topic
Author

need guidance on this exercise

Ricky James
Ranch Hand

Joined: Mar 26, 2007
Posts: 83
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 ]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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


[My Blog]
All roads lead to JavaRanch
Ricky James
Ranch Hand

Joined: Mar 26, 2007
Posts: 83
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Joined: Mar 26, 2007
Posts: 83
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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.
 
 
subject: need guidance on this exercise