Share This Tutorials Via Google Plus or Facebook (Help Friends)          

                                                            

                                                 





Pinterest

JSP Tutorial
JSP technology is used to create web application just like Servlet technology. It can be thought of as an extension to the servlet because it provides more functionality than servlet.

A JSP page contains HTML code and JSP tags. The jsp pages are easier to maintain than servlet because we can separate designing and development. It provides some additional features such as Expression Language, Custom Tag etc.

Advantage of JSP over Servlet

There are many advantages of JSP over servlet. These are as follows:

  1. JSP is the extension to the servlet technology. We can use all the features of Servlet in JSP. In addition to, we can use implicit objects, predefined tags, expression language and Custom tags in JSP, that makes JSP development easy.
  2. JSP can be easily managed because we can easily separate our business logic with presentation logic. In servet, we mix our business logic with the presentation logic.
  3. If JSP page is modified, we don’t need to redeploy the project. The servlet code needs to be updated and recompiled if we have to change the look and feel of the application.

Life cycle of a JSP Page

The JSP pages follows these phases:

  • Translation of JSP Page
  • Compilation of JSP Page
  • Classloading (class file is loaded by the classloader)
  • Instantiation (Object of the Generated Servlet is created).
  • Initialization ( jspInit() method is invoked by the container).
  • Reqeust processing ( _jspService() method is invoked by the container).
  • Destroy ( jspDestroy() method is invoked by the container).

Note: jspInit(), _jspService() and jspDestroy() are the life cycle methods of JSP.

jspflow

As depicted in the above diagram, JSP page is translated into servlet by the help of JSP translator. The JSP translator is a part of webserver that is responsible to translate the JSP page into servlet. Afterthat Servlet page is compiled by the compiler and gets converted into the class file. Moreover, all the processes that happens in servlet is performed on JSP later like initialization, commiting response to the browser and destroy.
Creating a simple JSP Page

To create the first jsp page, write some html code as given below, and save it by .jsp extention. We have save this file as index.jsp. Put it in a folder and paste the folder in the web-apps directory in apache tomcat to run the jsp page.

index.jsp
Let’s see the simple example of JSP, here we are using the scriptlet tag to put java code in the JSP page. We will learn scriptlet tag later.

<html>
<body>
<% out.print(2*5); %>
</body>
</html>

It will print 10 on the browser.

How to run a simple JSP Page ?

Follow the following steps to execute this JSP page:

  • Start the server
  • put the jsp file in a folder and deploy on the server
  • visit the browser by the url http://localhost:portno/contextRoot/jspfile e.g. http://localhost:8888/myapplication/index.jsp

Do I need to follow directory structure to run a simple JSP ?

No, there is no need of directory structure if you don’t have class files or tld files. For example, put jsp files in a folder directly and deploy that folder.It will be running fine.But if you are using bean class, Servlet or tld file then directory structure is required.
Directory structure of JSP

The directory structure of JSP page is same as servlet. We contains the jsp page outside the WEB-INF folder or in any directory.

jspdirectory

Share and Enjoy

  • Facebook

                                                                                                                                                                                           



Find Us on Facebook   



Recent Posts                



(2+ Years) "JP Morgan" Hiring: UX Designer On Jan 2017 @ Bangalore (Freshers) "Vodafone" Hiring: Backend Developer On Jan 2017 @ Pune (0 - 1 Years) "WowTables" Hiring: Front End Developer On Jan 2017 @ Mumbai (0 - 1 Years) "ManavManagement" Hiring: Female Counselor On Jan 2017 @ Faridabad (Freshers) "Social Beat" Hiring: Content Specialist On Jan 2017 @ Chennai (Freshers) "Barclays" Hiring: Developer On Jan 2017 @ Pune 0 - 3 Years) "Worldindia" Hiring: Web Administrator On Jan 2017 @ Mumbai (1 - 3 Years) "Etech Global" Hiring: .NET MVC Developer On Jan 2017 @ Baroda (3+ Years) "TheLogicFactory" Hiring: .NET Application Developer On Jan 2017 @ Ahmedabad (2 - 5 Years) "Tecra" Hiring: Software Engineer On Jan 2017 @ Hyderabad (2 - 4 Years) "Mphasis" Hiring: Testing Engineer On Jan 2017 @ Bangalore (3 - 5 Years) "Wipro" Hiring: Test Engineer On Jan 2017 @ Mumbai (3 - 5 Years) "Wipro" Hiring: Developer Core Java On Jan 2017 @ Bangalore (1 - 2 Years) "Nelito Systems" Hiring: Application Support Engineer On Jan 2017 @ Mumbai (Freshers) "RBS" Hiring: Senior Test Designer LastDate: 31st Jan 2017 @ Gurgaon (Fre/Exp) "Cisco" Hiring: Business Intelligence Analyst On Jan 2017 @ Bangalore (2 - 3 Years) "Amdocs" Hiring: Software Developer On Jan 2017 @ Pune (0 - 2 Years) "Emblix Solutions" Hiring: PhotoShop Designer On Jan 2017 @ Hyderabad (0 - 1 Years) "KD Groups" Hiring: Hr Trainee On Jan 2017 @ Gurgaon (0 - 2 Years) "SavvyonWeb" Hiring: Content Writer On Jan 2017 @ Noida (0 - 1 Years) "Signa" Hiring: Jr. Web Developer/Hr Executive On Jan 2017 @ Hyderabad (Freshers) "Zen Technologies" Hiring: Software Engineer On Jan 2017 @ Hyderabad (1 - 3 Years) "Geometric" Hiring: Teamcenter QA On Jan 2017 @ Pune (1 Years) "Rudra Softech" Hiring: Content Writer On Jan 2017 @ Ahmedabad (2 - 4 Years) "RAVSoft Solutions" Hiring: Software Engineer On Jan 2017 @ Chennai

Copyright © 2010 - 2012 . All rights reserved.
Please Note: careerbuzz.in is not in any way responsible for any consequences of you applying for a job through the vacancies listed on this site. Please do thorough research before applying. We take utmost care in publishing jobs on this site. While every care has been taken to avoid mistakes and errors on the web pages, careerbuzz.in shall not be liable to any person in any manner whatsoever by reason of any error or omission which might have crept in unintentionally
www.careerbuzz.in
Hi..VOTE US?