![]() For example, if your JSP is located at apache-`tomcat/webapps/test/home.jsp`, then you can access it in browser with URL ` If your host and port is different, then you need to make changes in URL accordingly. Just create a directory in the tomcat webapps folder and place your JSP file in the newly created directory. If you have a simple JSP that uses only JRE classes, we are not required to put it as WAR file. A simple JSP example page example is: `home.jsp` Please read (/community/tutorials/java-web-application-tutorial-for-beginners#first-web-app-servlet) tutorial to learn how can we easily create JSPs in Eclipse and run it in tomcat. We can use Eclipse IDE for building dynamic web project with JSPs and use Tomcat to run it. jspDestroy() declared in JspPage interface to unload the JSP from memory._jspService(HttpServletRequest request, HttpServletResponse response) declared in HttpJspPage interface and response for handling client requests.This method is called only once in JSP lifecycle to initialize config params. ![]() jspInit() declared in JspPage interface.Destroy - Last phase of JSP life cycle where it’s unloaded into memory.Request Processing - For every client request, a new thread is spawned with ServletRequest and ServletResponse to process and generate the HTML response.After initialization, ServletConfig and ServletContext objects become accessible to JSP class. Initialization - The JSP class is then initialized and it transforms from a normal class to servlet.Instance Creation - After JSP class is loaded into memory, its object is instantiated by the container.Class Loading - Once JSP is compiled as servlet class, its lifecycle is similar to servlet and it gets loaded into memory.Compilation - If the translation is successful, then container compiles the generated servlet source file to generate class file.If JSP file name is home.jsp, usually its named as home_jsp.java. Translation - JSP pages doesn’t look like normal java classes, actually JSP container parse the JSP pages and translate them to generate corresponding servlet source code.Usually every web container that contains servlet container also contains JSP container for managing JSP pages. JSP life cycle is also managed by container. We should use Servlet as server side controller and to communicate with model classes whereas JSPs should be used for presentation layer. For servlets, we need to recompile and deploy whole project again.Actually Servlet and JSPs compliment each other. JSP pages are easy to deploy, we just need to replace the modified page in the server and container takes care of the deployment.JSP provides additional features such as tag libraries, expression language, custom tags that helps in faster development of user views.JSP helps in this situation and provide us flexibility to write normal HTML page and include our java code only where it’s required. We can generate HTML response from servlets also but the process is cumbersome and error prone, when it comes to writing a complex HTML response, writing in a servlet will be a nightmare.This makes it easy to understand and helps a web developer to quickly develop JSP pages. To bridge the gap between java code and HTML in JSP, it provides additional features such as JSP Tags, Expression Language, Custom tags. Since web applications contain a lot of user screens, JSPs are used a lot in web applications. JSP Page consists of HTML code and provide option to include java code for dynamic content. JSP can be thought as an extension to servlet technology because it provides features to easily create user views. JSP (JavaServer Pages) is server side technology to create dynamic java web application. JSP transformed Servlet Source Code and Class File location in Tomcat JSP Files location in Web Application WAR File.Simple JSP Example with Eclipse and Tomcat.Some of these topics are very important and we will look into them in more detail in future posts. ![]() We will also look into the JSP Comments, Scriptlets, Directives, Expression, Declaration and JSP attributes in brief detail. ![]() In this JSP example tutorial, we will look into the basics of JSP, advantages of JSP over Servlets, Life Cycle of JSP, JSP API interfaces and Classes and where can we put JSP files in the web application. So I have started another series on JSP tutorials and this is the first post of the series. In last few posts, a wrote a lot about Java Servlet and got very good response from our readers. Welcome to the JSP Example Tutorial for Beginners.
0 Comments
Leave a Reply. |