Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Shopping cart servlet error  RSS feed

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, i have been working on trying to make this shopping card java program. First I tried doing requestmapping and parameters but after looking online I found some other ways that used servlets. While working on this code and running it, the index page is fine but when i press add to cart i get the white error page. I dont know where the logic could be wrong, any help would be great.



My cart page



and my html code

 
Sheriff
Posts: 23594
48
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That white error page: is it just a plain blank white page or does it have some information about an error?

If it has information on it, then it would be helpful if you posted that information, for anybody who wanted to answer your question.
 
Henna Ghayas
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the error message I am getting

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Wed Apr 04 15:29:50 EDT 2018
There was an unexpected error (type=Not Found, status=404).
No message available
 
Paul Clapham
Sheriff
Posts: 23594
48
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aha. So action="Addtocart" doesn't lead to your servlet, it leads nowhere. So check your configuration to see why that is. (From what you posted, I can't tell whether you used annotations to configure that servlet or whether you used a web.xml file). Also make sure your servlet is in a package, as servlets which are in the default package (i.e. don't have a package declaration at the top) won't work.
 
Saloon Keeper
Posts: 4560
115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also note that it's bad design to use a processRequest method that is called by both doGet and doPost. GET and POST are not interchangeable, and be used in different circumstances.

Adding something to a shopping cart should be done via POST, so you need to add that to your form declaration.
 
Henna Ghayas
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, i actually got it to work by your suggestion of the xml change
 
All of life is a contant education - Eleanor Roosevelt. Tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!