ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

Introduction to Java Server Pages:

Updated on November 6, 2014

Understanding the JSP techniques and uses:

When we talk or think about dynamic websites, there are some techniques which come in our mind. They are PHP, ASP.NET, and some other CMS are being used to design dynamic websites. Like these there are JSP and Java Servlets, Java Server Pages (JSP) and Java Servlets both are complementary techniques, these are used to build a fundamental part of the Java 2 Enterprise Edition (J2EE). J2EE is being used in a wide-ranging platform in the field of Enterprise development. By the help of these techniques we can build lot of APIs, a run time platform, and an ideal model for how to combine them in a best way. To take advantage of their features as scalable, portable, and well-developed applications.

We use localhost server to run the applications on our local computers. When we designed the websites so we don’t need to do anything for the website execution. Because everything is ready to use on server where we want to host our website.

There are list of servers which are being used for JSP and Java Servlets:

  1. Glassfish.
  2. Tomcat

These two are being used for the JSP webpages. You can download them from these links as if you want to use the Glassfish server so use this link: https://glassfish.java.net/download.html and if you want to use Tomcat server, it’s Apache product and its dedicated to JSP or Java Servlets as a localhost server. You can download it from this link: http://tomcat.apache.org/download-70.cgi

NOTE: sometimes it become difficult to install the servers for the dedicated technologies. I will suggest that when you are installing your IDE, for example if you are using Netbeans so during the install it will ask you about the servers to be install. So you can install them fully easy during the installation of the Netbeans installation. And it will set each thing by itself just what you will do after the installation. Go to create a new project and design it, and then run it. Your project will run successfully without any kind of errors related to server.

Benefits of the JSP:

There are lot of advantages of the JSP should be use. As we can use the JSP to the premise of what it built. That is to make less hard work for the developers to develop a website as dynamic in a possible way. We can use Java Programming inside the html tags to build dynamic website. It is a great feature of the JSP to design website using the Java Enterprise Technology. The developers are using the JSP as an Enterprise Technology to make satisfy of their customers. It is easy to search the problems of JSP, don’t go anywhere just use the Oracle’s website it will teach you as well as tell you the right and correct solution of your website problem. You can learn lot of things, because they are updating their official website day by day. So go and learn you can use this link: http://www.oracle.com/technetwork/java/javaee/jsp/index.html

Why JSP is necessary?

When we discuss about the webpages design programming. So there are lot of applications which are being used online. As they are being used for online transactions, updating, modifying etc. if we use JSP or servlets it will be a good choice due to its functions in networking and advantages of the easy development.

Comparison of JSP with other technologies:

If we simply compare JSP and Java servlets with each other so Java Servlets are so fast to be browse or execute than the JSP. It was a good platform to use the CGI, when the intrepid developers start writing their own server extension by the CGI. But there were also few of challenges. CGI was inefficient and complex scripting language. Active Server Pages (ASP), Microsoft tried its best to give relief the intrepid developers to write codes for the dynamics websites and use the extensions of the servers in their websites. But the ASP sometimes become the reason to crash and hang servers. So in this situations your website will not able to accessible. But the sun’s microsystems make it easy for developers to design and use the extensions of the servers.

To avoid the misconceptions of JSP:

There are lot of questions which are being asked by the developers which are new developers in the field of website designing. They mostly ask the experts as:

  1. How I can use swing component in JSP?
  2. How I can insert images in JSP?
  3. Tomcat is not supporting JavaScript I can’t use images as animation image?
  4. Sometimes browsers not support JSP?

Answers:

  1. Just simply use the applet and insert the Applet tag in your website
  2. Just simply use the IMG tag to insert your images, don’t need to use any I/O functions.
  3. Using JavaScript to change the images by the help of the mouse movement, so it will not happen due to server is running.
  4. It is not an issue the JSP webpages not viewing on web browsers, because they just show the output of the JSP. You should check the HTML tags.

Lifecycle of the JSP:

Understanding the lifecycle of JSP is easy and simple, the low-level functionality follow these paths:

  1. Compilation
  2. Initialization
  3. Execution
  4. Cleanup

JSP Life Cycle

Figure 1 Four Major Phases of JSP lifecycle
Figure 1 Four Major Phases of JSP lifecycle

Description of the JSP Paths of functionalities in JSP lifecycle:

  1. i. Compilation:

We need a localhost as a server to execute or compile the JSP pages on our local system. We use tomcat server to compile the JSP pages. During the execution of the JSP pages the server check the pages, rather executed or not. And also checks the last updated data on the pages. There are few steps which are being used to be processed the JSP pages.

  1. Parsing the JSP pages.
  2. Turning the JSP pages with servlet.
  3. Compiling the servlet.
  4. ii. Initialization:

There is a method which is used to initialize the JSP pages to invoke. The jsplnit() method is used for this purpose. And we should know the initialization once happen.

The syntax of the function is:

[code language="jsp"]

Public void jspInit(){

//statements here…

}

[/code]

  1. iii. Execution:

This phase will be active till the JSP request is not destroy. During the execution the JSP engine calls a JSP method to invoke or load the JSP pages. That’s why we use HttpServletRequest and HttpServletResponse in the JSP programs. The _jspService() method syntax is:

[code language="jsp"]

Public void _jspService(HttpServletRequest request, HttpServletResponse response){

//statements here….

}

[/code]

  1. iv. Cleanup

This is the phase which is called destruction in the JSP life cycle. There is a function which is jspDestroy(), it is equivalent to the destroy method of the servlets. We commonly override this methods, if we need to clean up the screen after the execution.

Syntax of the method:

[code language="jsp"]

Public void jspDestroy(){

//statements here

}

[/code]

Java Server Pages Tags:

There are total five tags which are being used in JSP.

  1. Declaration tag
  2. Expression tag
  3. Directive Tag
  4. Scriptlet tag
  5. Action tag

Declaration tag:

This tag is used to declare variables or methods any time during the development of the webpages. Syntax is:

[code language="jsp"]

<%!

Private String name = “JSP webpages”;

%>

[/code]

Comments

    0 of 8192 characters used
    Post Comment

    • profile image

      Nexon 2 years ago

      hello, friend i need one more about JSP...please do it as early as you can