wood burning stoves 2.0*
The moose likes Servlets and the fly likes Simple servlet: i need an explanation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Simple servlet: i need an explanation" Watch "Simple servlet: i need an explanation" New topic
Author

Simple servlet: i need an explanation

miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
in first place i want to apologize in case someone thinks i'm joking, because i'm not
when i started with java i didnt understand almost any of the terms of the "main" signature, but now i fully get it all

as to servlets, the doget and dopost methods are like that because they are? or there is an explanation? and who ever calls those methods?



where can i read about all this, from scratch?

thanks in advance


java amateur
Mario Alcantara
Greenhorn

Joined: Mar 29, 2011
Posts: 16
The method doPost and doGet have a purpose, the doPost method handle HTTP Post request and doGet handle HTTP Get request. Both methods are called by the service method, only one method is called at time, and depend on the http request type. If the request type is POST, the service method call doPost() method.

You can read the Head First Servlets & JSP by Bryan Basham, Kathy Sierra, Bert Bates second edition book. It´s clear and easy to understand
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2273
    
  28

GET and POST methods are part of the HTTP protocol which is the standard protocol for all communication on the web. The protocol defines how the client sends a request to the server and how the server responds to the request. What the J2EE web container does for you is hide the nitty gritty of the HTTP protocol from you. The J2EE server (tomcat/JBoss,etc) will take care of things like listening to incoming sockets from browsers, marshalloing the request and response, etc etc,and "wraps" the request and response in the HttpServletRequest and HttpServletResponse API.

The servlet that you implement execute inside the container, and whenever the container receives a request, it will parse the request and construct an HttpServletRequest and call your servlet. You servlet will perform the business logic and put the response in HttpServletResponse. After your method returns the container will marshal your response as a HTTP response and send it back to the client.
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

miguel lisboa wrote:
as to servlets, the doget and dopost methods are like that because they are? or there is an explanation? and who ever calls those methods?

Yes the doXXX() methods carry the signature you mentioned, these are invoked by the servlet container based on the type of HTTP request received.
For more info see service methods and servlet container .


SCJP, SCWCD.
|Asking Good Questions|
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
Mario Alcantara wrote:(...)You can read the Head First Servlets & JSP by Bryan Basham, Kathy Sierra, Bert Bates second edition book. It´s clear and easy to understand

that was one of my first thoughts; later i dropped the idea because it looked to me a lot like exam oriented, and as i'm a pure amateur...


Jayesh A Lalwani wrote:GET and POST methods are part of the HTTP protocol which is the standard protocol for all communication on the web. The protocol defines how the client sends a request to the server and how the server responds to the request. What the J2EE web container does for you is hide the nitty gritty of the HTTP protocol from you. The J2EE server (tomcat/JBoss,etc) will take care of things like listening to incoming sockets from browsers, marshalloing the request and response, etc etc,and "wraps" the request and response in the HttpServletRequest and HttpServletResponse API.

The servlet that you implement execute inside the container, and whenever the container receives a request, it will parse the request and construct an HttpServletRequest and call your servlet. You servlet will perform the business logic and put the response in HttpServletResponse. After your method returns the container will marshal your response as a HTTP response and send it back to the client.

that's perfect!

as to Amit's links, i have to say i am in the process of reading the 6th ed of java ee tutorial, in pdf, which, in the case you point to, is quite diferent from your 5th ed (note the tut has more then 1000 pages and i'm still around page 100)

but what really clarified my head and showed (finally) how things work behind the scenes was the onjava article: now i have a much clearer idea of what's going on and also i understand what i didnt when i first wrote this topic

thanks to everyone who helped me
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simple servlet: i need an explanation
 
Similar Threads
Problem bookmarking page with doGet method.
Overriding the doGet and doPost Methods in servlet
Connection Object
doXXX methods
Using a variable before it has been initialised