Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doPost() not working

 
tushar attar
Ranch Hand
Posts: 36
Chrome Java Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am learning servlet and following a tutorial. Here we create two servlet which communicates with each other. One servlet take post request from html form and forward the result to other servlet using requestdispatcher applies some more logic and display the result. But when i click on submit button on html fom i get  "HTTP Status 405 - HTTP method POST is not supported by this URL" error. My codes are

basic.html




GrossServlet.java




NetServlet.java



web.xml



Same code run in tutorial but i am getting error, please tell me where i am wrong.


 
Paul Clapham
Sheriff
Posts: 21581
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For one thing your servlets have to be in a package. Without that you can't even run them, and that probably results in the not-all-that-helpful error message. There may well be other problems but start by fixing that. And don't forget to specify the servlet's fully-qualified name including package in your web.xml file.
 
tushar attar
Ranch Hand
Posts: 36
Chrome Java Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for a reply, i am currently following a tutorial and in that they didn't used a package.
 
Paul Clapham
Sheriff
Posts: 21581
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It must be a really old tutorial.

Anyway, if you were working for an aggressive boss who refused to let you use packages, then you'd have to spend some time trying to work around the requirement for a package name. But you aren't. So just use a package already like everybody else in the world.
 
Rob Spoor
Sheriff
Pie
Posts: 20753
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tushar attar wrote:

That's not an override but an overload. The arguments should be HttpServletRequest and HttpServletResponse. Right now there is no doPost implementation, which means the default implementation kicks in. Guess what? That returns a 405 error.

Here's a tip: annotate all your overridden methods with @Override. If it's not a proper override (or interface method implementation), you'll get a compiler error, and you'll know immediately you did something wrong.
 
tushar attar
Ranch Hand
Posts: 36
Chrome Java Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for pointing out error, I corrected it still no success
 
tushar attar
Ranch Hand
Posts: 36
Chrome Java Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I just corrected one more error , i created in later stage and it resolved the problem. Thanks Rob your solution did help.
 
Rob Spoor
Sheriff
Pie
Posts: 20753
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic