File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple servlet: i need an explanation

 
miguel lisboa
Ranch Hand
Posts: 1281
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mario Alcantara
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2851
10
Fedora Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
miguel lisboa
Ranch Hand
Posts: 1281
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic