0% found this document useful (0 votes)
2 views4 pages

JSP

JSP technology extends servlet technology by providing additional functionalities like JSTL and Expression Language, making web application development easier and more maintainable. It allows for a clear separation of business and presentation logic, enabling faster development without the need for recompilation. JSP scripting elements include declaration, expression, and scriptlet tags, while directives guide the web container in processing JSP pages.

Uploaded by

K Suresh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

JSP

JSP technology extends servlet technology by providing additional functionalities like JSTL and Expression Language, making web application development easier and more maintainable. It allows for a clear separation of business and presentation logic, enabling faster development without the need for recompilation. JSP scripting elements include declaration, expression, and scriptlet tags, while directives guide the web container in processing JSP pages.

Uploaded by

K Suresh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

 JSP technology is used to create web application just like servlet technology.

 JSP is an extension to Servlet because it provides more functionality than servlet such as JSTL
expression language(EL),, etc.
 A JSP page consists of HTML tags 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 tags, etc.,

Advantages of JSP:

1) Extension to servlet:

JSP technology is the extension to servlet technology. We can use all the features of the 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) Easy to Maintain:

JSP can easily managed because we can easily separate our business logic with presentation logic. In
servlet technology, we mix our business logic with the presentation logic.

3) Fast Development:

No need to recompile and redeploy

If JSP page is modified, we don’t need to recompile and redeploy the project. The servlet code needs to
be updated and recompiled if we have to change the look and feel of the application.

4) Less Code than Servlet:

In JSP, we can use many tags such as action tags, custom tags, etc, that reduces the code. Moreover, we
can use EL, implicit objects, etc.,

JSP Scripting Elements


The scripting elements proves the ability to insert java code inside JSP. There are three types of scripting
elements

1. Declaration tags

<%! int a=5; String name=”sreedhar”; public void show() { } %>

2. Expression tags

<%= a %> <%= name %>

3. Scriptlet tags

<% req.getParameter(); %>


Index.jsp:

<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Hello World</h1>

<h1>Declaration Tags</h1>

<%! int a=10;String name="sreedhar"; %>

<h1>Expression Tags: <%= a %> <%=name%> </h1>

<h1>Scriptlet Tags:

<% int sum=20+30;


//out.println("Sum = "+sum);
%> </h1>

<h1>sum=<%=sum %></h1>
</body>
</html>

JSP Directive:

The JSP directives are messages that tells the web container how to translate a JSP page into the
corresponding servlet:

There are three types of directives:

1. Page directive
<%@ page attribute=”value”%>
Arrtibutes of page directives:
 import
 content type
 extends
 info
 buffer
 language
 isELIgnored
 isThreadSafe
 autoFlush
 session
 pageEncoding
 errorPage
 isErrorPage
2. Include directive

Current Date:
Index.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-


8859-1"
pageEncoding="ISO-8859-1"%>

<%@ page import="java.util.*" %>

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Hello World</h1>

<%@include file="header.jsp" %>

<h1>Time: <%=new Date().toString() %></h1>

</body>
</html>
Header.jsp:
<h1 style="color:black;padding:20px">Header Page</h1>

3. Taglib directive

Select the Maven Project

NewMaven ProjectNextCatalog=internalselect org.apache.maven.archetypes maven-archtype-


webapp 1.0  Group ID : com.sreedhar (nothing but package name) Artifact ID: JSP-Directive-App
(nothing but project name)  package : com.sreedhar  Finish

You might also like