.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> General >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Introduction to Java server pages

Posted By:satyapriyanayak       Posted Date: August 15, 2014    Points: 200    Category: General    URL: http://www.dotnetspark.com  

In this article we will know about Java server pages.
 

It is a mechanism to create dynamic web pages by using servlet behind it. Whenever a user comes to access the jsp then the web server converts the jsp into a servlet for processing the request and providing response.


Features of jsp


1.Interpreted:- A jsp does not need explicit compilation. A programmer needs to create the jsp and store it into the context folder. Whenever the jsp gets accessed by the first user then the web server creates a servlet and complies it to create required class file. The generated servlet gets loaded into the servlet container for processing request and for providing reponse. Hence the jsp does not need explicit compilation.


2.Object based:- Jsp cannot implement inheritance and polymorphism. It can use a set of predefined objects such as request, response and out without creating those explicitly.


3.Tag based:- It can use a set of tags to perform any task in the server. These tags can be predefined or user defined.


4.User friendly:- A jsp contains java code inside html tags. The required html tags can be generated with the help of any html editor. The required java code can be inserted into the generated html tags. This makes the jsp creation faster and easier.


Possible content of a Jsp


1.Directive:- This can be used in a jsp to include or import any external file or package into the jsp.


Syntax:-

< %@ directiveName  attribute="value" %>

Ex:- <%@ page import="java.sql.*" %>


2.Declaration section:- This section can be used in a jsp to declare page scope variables and methods. This section can appear before any html tags.


Syntax:-

<%! Declaration of variables or methods %>

Ex:- <%! int x=100; %>


3.Html tags:- These tags appear in a jsp like any ordinary html file. These can be used to represent any content to the user.


4.Scriptlets:- This section contains executable java code. This can appear in any place for any number of times in a jsp.


Syntax:-

<% Java code %>


5.Jsp tags:- This tags can appear to perform any task in the server. This tags cannot appear inside Scriptlets.This tags follow xml syntax.


Ex:- <jsp:forward page="./test.jsp" />


6.Expression:- This can appear in a jsp to print value of a variable or result of an expression into the response.


Syntax:- 

<% = Expression or variable %>

Ex:- <H1>Welcome<% = str %></H1>


Creation process of Jsp


1.Create a file by using .jsp extension in the context folder.


2.Provide the required html tags as any ordinary html file.


3.Provide the required java code inside the html tags by using the following syntax below

<% Java code %>


Ex:- Program to show Hello JSP 5 times .


Hello.jsp


<html>

<body bgcolor="pink">

<%

   for(int i=0;i<5;i++)

   {

  out.println("<h2>Hi:</h2>");

 %>


 <h2>Hello JSP</h2>


<%

   }

 %> 

</body>

</html>


Running the application


Run the tomcat then write the below line in the Url

http://localhost:8081/jsp/


Here jsp is the Context path, which we mentioned in the server.xml file, which is present in (E:\Program Files\Apache Software Foundation\Tomcat 6.0\conf) directory.


After giving the url a set a listing will come, here only one appears

As Hello.jsp,click it


http://localhost:8081/jsp/Hello.jsp



 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend