The JSP is translated into the appropriate Servlet code, which is a .java file. Many application servers provide the option of keeping the generated .java files. Once it is translated into the .java file it is compiled into the bytecode file (.class). The .class file is executed and the output HTML document is generated and sent back to the client.
To translate code bewteen JSP to Servlet:
1. JSP scriptlet (i.e., <% scriptlet %>) and experssion (i.e., <%= expression%>), when translated into a servlet, will end up in the body of doGet or doPost method.
2. JSP declaration (i.e., <%! declaration %>), when translated into a servlet, will end up being instance variables or methods in the servlet class.
3. A variable defined inside of a JSP declaration could translate to an instance variable and a variable defined inside of a JSP scriptlet could translate to a local variable in doGet or doPost method.
4. U may have jspInit() or jspDestroy() methods defined in the JSP declaration. They are equivalent to Servlet’s init() and destory() methods.