File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes doPost() is not called in servlet logic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "doPost() is not called in servlet logic" Watch "doPost() is not called in servlet logic" New topic
Author

doPost() is not called in servlet logic

bubu lina
Greenhorn

Joined: Aug 11, 2008
Posts: 28
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

Joined: Aug 03, 2008
Posts: 9302
    
  17

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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
bubu lina
Greenhorn

Joined: Aug 11, 2008
Posts: 28
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

Joined: Aug 11, 2007
Posts: 140

in the JSP remove the "/" in the "action" attribute.

<form action="RuntimeServlet" method="POST">


SCJA, SCJP, SCJD, SCMAD, SCWCD, SCBCD, SCDJWS, SCEA, SOA, Spring Certified, OCP MySQL 5 Developer, PMP
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61180
    
  66

Sloppy. The URL should be fully specified beginning with the context path of the web application.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
bubu lina
Greenhorn

Joined: Aug 11, 2008
Posts: 28
you were right, removed the "/" and it worked. thank you.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9302
    
  17

As Bear said, the URl must generally start with / and must contain the context path. You can change your URL to

Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

or you can use the core taglib <c:url> tag



I love this place!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61180
    
  66

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.
 
 
subject: doPost() is not called in servlet logic