• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doPost() is not called in servlet logic

 
bubu lina
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
My problem is this.
- i have a jsp page with a <form action="/etc" method="POST">..</form>
- i have a servlet: XServlet.java in which i override the doGet() and the doPost() methods.
- in my form i have some submit buttons...one for each table
- because i have the method declared to be on POST i thought that in my servlet i don't have to do anything else just write my logic in doPost method:P
Everything i do in my jsp page...all is going to the doGet method.(?!)



Searching the internet i found this: http://forums.sun.com/thread.jspa?threadID=5396213:
doGet method is called by the server (via the service method) to allow a servlet to handle a GET request.
As the form was submitted using POST method, doGet method won't get called and hence it won't print anything.

neither doPost.


I don't get it. what am i doing wrong here? any ideas would make my day and make me learn something today.

Thank you in advanced
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you provide us the relevant part of the JSP page and the XServlet.java. Also you gave the code in which you were getting out the request method, were you getting GET as the output?? There might be a mistake somewhere in the code which we can only see after seeing the code...
 
bubu lina
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jsp:


xservlet.java:


there is more logic in them, but what i need is to simply see from the doPost my system out message. to the logic implemented in doGet i get no errors.
thank you
 
kurt hanni
Ranch Hand
Posts: 140
Eclipse IDE Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in the JSP remove the "/" in the "action" attribute.

<form action="RuntimeServlet" method="POST">
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sloppy. The URL should be fully specified beginning with the context path of the web application.
 
bubu lina
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you were right, removed the "/" and it worked. thank you.
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Bear said, the URl must generally start with / and must contain the context path. You can change your URL to

 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or you can use the core taglib <c:url> tag

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bubu lina wrote:you were right, removed the "/" and it worked. thank you.

Just because it works, doesn't make it good code. It's sloppy and fragile.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic