Results 1 to 7 of 7
- 09-14-2009, 04:23 PM #1
Member
- Join Date
- Sep 2009
- Posts
- 1
- Rep Power
- 0
doPost() is not called in servlet logic
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.(?!)
"
String requestType = request.getMethod(); System.out.println("reqType(dinGet): " + requestType);"
Searching the internet i found on the sun forums this:
"
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 :)
- 09-27-2009, 03:18 AM #2
are you sure you have overridden the doPost method, such as
in that if you typod the doPost() or didnt have exact expected method signature, which I always used to do. Before they had those java 1.5 @Override things, which cause compile errors if it is not really overriding. ; using a different signature to not cause it to be overridden will allow the default doPost() on HttpServlet to invoke, which should actually return a not supported http status code.Java Code:@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { }
im stumped.
have not overridden the service() method right ?
i guess too make sure the form rendered METHOD="POST" is not typo'd
and that if there is any javascript to do this.form. validation, that nothing is inadvertently setting this.form.method='get' on you.
other crazy ideas, if there is a http proxy server between your browser and the webapp , could that thing possibly be converting posts to gets ?
- 10-28-2009, 06:42 AM #3
Member
- Join Date
- Oct 2009
- Location
- Indore,MP ,India
- Posts
- 3
- Rep Power
- 0
hi,
have you override service method in your code if yes then you will lose the
functionality provided by the HttpServlet class, and the doXXX()
methods will not be called automatically. In your implementation, you will
have to determine the HTTP method used in the request, and then you will
have to call the appropriate doXXX() method yourself.
One thing more if you don't override service() ,then double check the signature of your doPost() .
Regards,
Naresh Bahety
Indore India.
- 10-28-2009, 08:54 AM #4
whether ur class extends HTTPServlet?
Ramya:cool:
- 10-28-2009, 09:39 AM #5
Member
- Join Date
- Oct 2009
- Posts
- 2
- Rep Power
- 0
hi,
if u r using HttpServlet,
1.public void init(ServletConfig config)throws ServletException
---for storing ServletConfig obj
2.public void init() throws ServletException
---for giving extra functionality we can override.
3.public void service(ServletRequest req,ServletResponse resp) throws ServletException,IOException
webcontainer always calls this method(lifecycle method)
in this request,response objects typecast into HttpServeltRequest,HttpServeltResponse object,and then calls
4.protected void service(HttpServeltRequest hreq,HttpServeltResponse hresp) throws ServletException,IOException
in this method contains default implementation(for generating 404 status code) for all doXXX() methods--GET,POST,HEAD,OPTIONS,PUT,TRACE,DELETE.
by using hreq.getMethod()--webcontainer identifies which method has to execute.
so override properly protected void service(HttpServletRequest hreq ,HttpServlerResponse hresp) throws ServletException,IOException,
and doXxx(HttpServletRequest hreq ,HttpServlerResponse hresp) throws ServletException,IOException,
- 10-28-2009, 09:50 AM #6
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
- 10-28-2009, 10:19 AM #7
Member
- Join Date
- Oct 2009
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
javascipt function is nt getting called
By pankaj_salwan in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 12-20-2008, 08:13 AM -
Disallow doPOST method in Sun Application server
By prakash_sahoo in forum Advanced JavaReplies: 5Last Post: 08-28-2008, 06:54 AM -
Setting cookie from doPost
By Java Tip in forum Java TipReplies: 0Last Post: 01-25-2008, 07:08 PM -
About doGet & doPost methods
By amitnayak1 in forum Java ServletReplies: 3Last Post: 12-04-2007, 07:02 AM -
doPost question
By Heather in forum Java ServletReplies: 1Last Post: 07-09-2007, 03:13 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks