• 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

Simple servlet: i need an explanation

 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I guess I've been abducted by space aliens. So unprofessional. They tried to probe me with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic