• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help : Servlet Service Method

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear all,

I have one html page which calling a servlet. In this servlet service method is overridden. In form tag of html page method is either GET or POST. So after I click submit button in html page it calls servlet and servlet executes. So how this happens?

I am also giving code below

Test.html

<HTML>
<HEAD>
</HEAD>
<BODY>
<form name="e" method="POST" action="/servlet/TestServlet">
<INPUT TYPE="submit" value="Submit">
</form>
</BODY>
</HTML>

On submit it is calling TestServlet

package com.test.servlet;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;


public class TestServlet extends HttpServlet
{
public void service(HttpServletRequest Req,HttpServletResponse Res)
{
try
{
PrintWriter out = Res.getWriter();
out.println("http://www.javaranch.com");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

How this service method written in servlet is identifying get or post method?

regards,
Amit Kulkarni
[ July 07, 2005: Message edited by: AmitVijay AVKulkarni ]
 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The defualt implementation of service method checks for the HTML form's method and it forward to GET and POst depending on method's type.But since your are overriding the service method, The new code will be executed insted of checking for method's type.
No errors, just works fine.
 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the actual code of HttpServlet's service() method default implementation. request.getMethod() method is used to determine the type of method used by client browser while it invoked the service:
reply
    Bookmark Topic Watch Topic
  • New Topic