Servlets and JSPs were important for long time, but some concepts are very important and curious and may not gain the proper attention. How a JSP page turns into an HTML page? How can we work directly with the HTML instead of JSP (like the Thymeleaf)?
Java Server Pages, that are template engines. On it, it’s possible to write Java code either directly (scriptlets) and with JSTL / taglibs, and you can get parameters / objects passed through a Servlet.
Java classes that are responsible for dealing with requests from Web clients, such as the browsers.
- Web Container (Servlet Container)
It is a component of a web server that interacts with Java Servlets. It is the container that delivers the servlet the request and the HTTP response, and calls servlet methods (such as doPost or doGet).
How JSP turns into HTML with filled data?
When a JSP is requested, the Web Server uses a JSP compiler and converts the JSP into a Servlet that implements the interface javax.servlet.jsp.JspPage.
O arquivo JSP é compilado somente quando a página é requisitada pela primeira vez ou quando o arquivo JSP é alterado, ou seja, o Servlet gerado a partir do JSP é reutilizado, fazendo as próximas chamadas serem mais rápidas.
The JSP file is compiled only when the page is first requested or when the JSP file is changed, i.e., the Servlet generated from the JSP is reused, making the next calls faster.
But how so? The Web Server that transforms the JSP?
That’s right. The Web Server transforms the JSP into a Servlet.
But what about my Servlet? And what’s that getRequestDispatcher? Continue reading