Results 1 to 7 of 7
  1. #1
    bubulina is offline Member
    Join Date
    Sep 2009
    Posts
    1
    Rep Power
    0

    Question 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 :)

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    are you sure you have overridden the doPost method, such as
    Java Code:
    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
    }
    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.

    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 ?

  3. #3
    nareshbah is offline Member
    Join Date
    Oct 2009
    Location
    Indore,MP ,India
    Posts
    3
    Rep Power
    0

    Default

    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.

  4. #4
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    841
    Rep Power
    6

    Default

    whether ur class extends HTTPServlet?
    Ramya:cool:

  5. #5
    p.sowmya is offline Member
    Join Date
    Oct 2009
    Posts
    2
    Rep Power
    0

    Post

    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,

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Quote Originally Posted by p.sowmya View Post
    ...

    so override properly protected void service(HttpServletRequest hreq ,HttpServlerResponse hresp) throws ServletException,IOException,
    and doXxx(HttpServletRequest hreq ,HttpServlerResponse hresp) throws ServletException,IOException,
    No. Don't override the service method at all. There is almost never a reason to do that.

  7. #7
    p.sowmya is offline Member
    Join Date
    Oct 2009
    Posts
    2
    Rep Power
    0

    Default

    check the syntax of doGet(...,...)....,
    doPost(...,...)....
    extending HttpServlet.
    and in jsp <form> tag

Similar Threads

  1. javascipt function is nt getting called
    By pankaj_salwan in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 12-20-2008, 08:13 AM
  2. Disallow doPOST method in Sun Application server
    By prakash_sahoo in forum Advanced Java
    Replies: 5
    Last Post: 08-28-2008, 06:54 AM
  3. Setting cookie from doPost
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-25-2008, 07:08 PM
  4. About doGet & doPost methods
    By amitnayak1 in forum Java Servlet
    Replies: 3
    Last Post: 12-04-2007, 07:02 AM
  5. doPost question
    By Heather in forum Java Servlet
    Replies: 1
    Last Post: 07-09-2007, 03:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •