
So, yeah, I summed up all what I understood and drew a simple diagram.
If I am not wrong, the servlet is the CGI (Common Gateway Interface) because the servelet is THE ONLY way you can get access to the resources on the server. So, in short, it is the COMMON GATEWAY.
The CONTAINER, like Apache Tomcat, is responsible for capturing the request sent by the user and sending it to the servlet.
What the user perceives is a dynamic webpage called web app.
This is what I learnt so far.
Have I learnt it correctly ?
You are almost right. Here are typical workflows you can follow when working with plain servlets:
Servlet renders page
Servlet container find servlet that matches request URL
doGet()ordoPost()is called depending on HTTP method requestedServlet does some processing
Response (HTML, XML, JSON, image…) is generated directly in the servlet and sent to the client using
getOutputStream()orgetWriter()JSP handles request
Servlet container finds JSP matching request. You must understand that underneath each JSP is translated to some internal servlet
This JSP is interpreted. Raw text is sent directly, Java code in scriptlets is executed
JSP ends, request is done
Servlet forwards to JSP
Same as 1-3 in first scenario
Servlet chooses JSP file and forwards to that JSP
JSP file is then evaluated, it has access to some context (request attributes, session) that was passed by servlet
The last scenario is considered the best one as it does not mix business logic (servlet) and presentation (JSP).