What is JSP? Discuss with suitable example.
JavaServer Pages simplify the delivery of dynamic Web content. They enable Web application programmers to create dynamic content by reusing predefined components and by interacting with components using server-side scripting. Custom-tag libraries are a powerful feature of JSP that allows Java developers to hide complex code for database access and other useful services for dynamic Web pages in custom tags. Web sites use these custom tags like any other Web page element to take advantage of the more complex functionality hidden by the tag. Thus, Web-page designers who are not familiar with Java can enhance Web pages with powerful dynamic content and processing capabilities.
The classes and interfaces that are specific to JavaServer Pages programming are located in packages:- javax.servlet.jsp and javax.servlet.jsp.tagext.
A Simple JSP Example
JSP expression inserting the date and time into a Web page.
//test.jsp
<html>
<head>
<meta http-equiv = "refresh" content = "60" />
<title>A Simple JSP Example</title>
<style type = "text/css">
.big { font-family: helvetica, arial, sans-serif;
font-weight: bold;
font-size: 2em; }
</style>
</head>
<body>
<p class = "big">Simple JSP Example</p>
<table style = "border: 6px outset;">
<tr>
<td style = "background-color: black;">
<p class = "big" style = "color: cyan;">
<!-- JSP expression to insert date/time -->
<%= new java.util.Date() %>
</p>
</td>
</tr>
</table>
</body>
</html>
OR,
Java Server Pages (JSP) is server-side technology to create a dynamic java web applications. It allows java programming code to be embedded in the HTML pages.
Scripting elements are used to provide dynamic pages.
JSP simply puts Java inside HTML pages.
JSP provides the following scripting elements:
1. JSP Comments:
Syntax:
<%-- comments --%>
2. JSP Scriplet:
A scriptlet tag is used to execute java source code in JSP.
Syntax:
<% java source code; %>
3. JSP Expression:
JSP expression can be used to insert a single java expression directly into the response message. This expression will be place inside a out.print() method.
Syntax:
<%= Java Expression %>
4. JSP Declaration: JSP declaration tag is used to declare variables and methods.
Syntax:
<%! Variable or method declaration %>
Example
Comments
Post a Comment