The Intro of JSP
- An extension of the servlet technology which offers both scripting ( as in HTML) as well as programming (as in Servlets)
- When a JSP page is requested, the JSP container ( also called page compiler) compiles the jsp page into a servlet class.
- The JSP API that handles all the JSP technology has been bundled under the following two packages:
- javax.servlet.jsp
- javax.servlet.jsp.tagext
A JSP page is all about JSP tags and some template data ( such as HTML tags). That's pretty much of it. It always feels good learning about JSP as we get to see the very well-know HTML tags (I presumed that you already know HTML at this point).
JSP consists of three types of elements.
- Directive elements
- Scripting elements
- Action elements
<%@ directiveName (attributeName="atrributeValue")
%>
|
These are the messages/information to the JSP container on how it should translate the JSP page into the corresponding servlet.
Again, there are three types of directives:
- Page directives
- Include directives
- Tag library directives
1. Page Directive
<%@ page (attributeName="atrributeValue") %>
<%@ page (attributeName="atrributeValue") %>
You might have encountered some "import" statements at the beginning of some JSP pages. Those import statements falls under this category. E.g.
<%@ page import="java.util.Date, java.util.Enumeration" language="java" %>
where,
page => represents directiveName
import/language => represents attributeName
and the values enclosed by quotes represents atrributeValue
The following is the list of available Page directive attributes:
<%@ page import="java.util.Date, java.util.Enumeration" language="java" %>
where,
page => represents directiveName
import/language => represents attributeName
and the values enclosed by quotes represents atrributeValue
The following is the list of available Page directive attributes:
Attribute
|
Value
Type
|
Default
Value
|
language
|
Scripting
language name
|
"java"
|
info
|
String
|
Depends on the
JSP container
|
contentType
|
MIME type,
character set
|
"text/html;charset=ISO-8859-1"
|
extends
|
Class name
|
None
|
import
|
Fully qualified
class name or package name
|
None
|
buffer
|
Buffer size or
false
|
8Kb
|
autoFlush
|
Boolean
|
"true"
|
session
|
Boolean
|
"true"
|
isThreadSafe
|
Boolean
|
"true"
|
errorPage
|
URL
|
None
|
isErrorPage
|
Boolean
|
"false"
|
NOTE:
|
|
Page Attributes a little in-depth:
- language
- <%@ page language="java" %>
- The only supported language by Tomcat JSP Container
- Other JSP containers might accept different languages
- info
- <%@ page info="any string here" %>
- Can be retrieved by calling the method getServletInfo() from anywhere withing the page
- contentType
- <%@ page contentType="application/json; charset=UTF-8" %>
- Defines MIME type of the HTTP response sent to the client
- extends
- <%@ page extends="yourClass" %>
- Defines the parent class that will be inherited by the generated servlet of the current page
- This attribute is less common
- import
- <%@ page import="java.io.*" %>
- One of the most common attributes used
- Same as we do in java classes/interfaces
- By default, tomcat imports the following packages:
- javax.servlet.*
- javax.servlet.http.*
- javax.servlet.jsp.*
- javax.servlet.jsp.tagext.*
- org.apache.jasper.runtime.*
- buffer
- <%@ page buffer="none" %>
- <%@ page buffer="20kb" %>
- <%@ page buffer="20" %>
- buffer="20" is the same as "20kb"
- But it's up to the JSP container to use its discretion to increase the buffer in order for the improved performance
- autoFlush
- <%@ page autoFlush="false" %>
- If true, the JSP container automatically flushes the buffer when it's full.
- If false, the buffer can be flushed manually by the following statement:
- out.flush()
- session
- <%@ page session="true" %>
- By default, the session is set "true", meaning the JSP page takes part in session management
- It is wise and strongly advised not to set it true unless you specifically require it because this consumes resources.
- isThreadSafe
- <%@ page isThreadSafe="true" %>
- True indicates that the simultaneous access to this page is safe
- False indicates that the simultaneous access to this page is not safe. In that case, the JSP container puts multiple requests in a queue and serves them only one at a time.
- errorPage
- <%@ page errorPage="MyErrorPage.jsp" %>
- Indicates the error page which is displayed if an uncaught exception occurs in the current page
- The error page must have the page attribute isErrorPage="true"
- isErrorPage
- <%@ page isErrorPage="true" %>
- If true, then only be set as an error page in other JSP pages
- If true, this page has an access to the exception implicit object
2. Include directives
SCRIPTING ELEMENTS
<%@ include file="includes/Footer.html" %>
- As the name suggest, Include Directive enables us to include the contents of other files in the current JSP page.
- The included page can be static HTML page as well as dynamic JSP page.
- Very commonly used to include Header page, Footer page or a page containing import statements and so on.
2. Taglib directives
- The taglib, or tag library, directive can be used to extend JSP functionality. It's a broad topic so it's not covered here at this moment. It will be covered under it's own topic later soon.
SCRIPTING ELEMENTS
Scripting elements allow you to insert Java code in your JSP
pages. There are three types of scripting elements:
-
Scriptlets
-
Declarations
-
Expressions
1. Scriptlets
<% ... %>
- Syntax looks similar to Directives. But don't get confused, Directives starts with <%@ i.e. <%@ ... %>
<%
try {
Class.forName("com.mysql.jdbc.Driver");
System.out.println("JDBC driver
loaded");
}
catch (ClassNotFoundException e) {
System.out.println(e.toString());
}
%>
...
...
<%
out.println("You can
do anything here");
String str = "some
string";
str = str + " string
concatenation";
out.println( str );
%>
|
2. Declarations
<%! ... %>
- Used to declare methods and variables that can be used from any point in the JSP page.
- Can appear anywhere throughout the page. For instance, a method declaration can appear above a page directive that imports a class, even though the class is used in the method.
<%!
String getSystemTime() {
return
Calendar.getInstance().getTime().toString();
}
%>
<%@ page
import="java.util.Calendar" %>
<%
out.println("Current Time: " +
getSystemTime());
%>
|
<%= ... %>
- Expressions get evaluated when the JSP page is requested and their results are converted into a String and fed to the print method of the out implicit object.
- If the result cannot be converted into a String, an error will be raised at translation time. If this is not detected at translation time, at request-processing time, a ClassCastException will be raised.
- Don't need to add a semicolon at the end of an expression
Below is the two equivalent statements:
<!-- Expression -->
<%= java.util.Calendar.getInstance().getTime()
%>
<!-- Equivalent
Scriptlet -->
<%
out.print(java.util.Calendar.getInstance().getTime()); %>
|
TO BE CONTINUED...
The main motive of the Big data app development is to spread the knowledge so that they can give more big data engineers to the world.
ReplyDeleteManoj Shrestha'S Blog: Jsp Basics >>>>> Download Now
ReplyDelete>>>>> Download Full
Manoj Shrestha'S Blog: Jsp Basics >>>>> Download LINK
>>>>> Download Now
Manoj Shrestha'S Blog: Jsp Basics >>>>> Download Full
>>>>> Download LINK
https://bayanlarsitesi.com/
ReplyDeleteFiruzköy
Başıbüyük
Karadeniz
Taşdelen
5G7XS
B1DBA
ReplyDeleteAntep Parça Eşya Taşıma
Samsun Evden Eve Nakliyat
Yalova Lojistik
Uşak Evden Eve Nakliyat
Bayburt Evden Eve Nakliyat
25992
ReplyDeleteArtvin Parça Eşya Taşıma
Samsun Evden Eve Nakliyat
Trabzon Lojistik
Kırıkkale Lojistik
Ardahan Parça Eşya Taşıma
Şırnak Parça Eşya Taşıma
Probit Güvenilir mi
Zonguldak Şehir İçi Nakliyat
Sakarya Evden Eve Nakliyat
23D8F
ReplyDeleteTokat Evden Eve Nakliyat
Bitcoin Nasıl Alınır
Kırıkkale Şehir İçi Nakliyat
Nevşehir Şehir İçi Nakliyat
Kırklareli Parça Eşya Taşıma
Muğla Parça Eşya Taşıma
Bilecik Parça Eşya Taşıma
Yenimahalle Parke Ustası
Tokat Lojistik
D1C86
ReplyDeleteKalıcı Makyaj
Bitmex Güvenilir mi
Tekirdağ Çatı Ustası
Antep Parça Eşya Taşıma
Diyarbakır Evden Eve Nakliyat
Tokat Lojistik
Malatya Şehir İçi Nakliyat
Silivri Cam Balkon
Sinop Şehirler Arası Nakliyat
470BD
ReplyDeleteKırşehir Evden Eve Nakliyat
Urfa Evden Eve Nakliyat
Ünye Evden Eve Nakliyat
oxandrolone anavar for sale
İzmir Evden Eve Nakliyat
anapolon oxymetholone for sale
Ağrı Evden Eve Nakliyat
Eskişehir Evden Eve Nakliyat
deca durabolin
BD227
ReplyDelete%20 komisyon indirimi
EFB05
ReplyDeleteBinance Referans Kodu
Soundcloud Dinlenme Hilesi
Meta Coin Hangi Borsada
Alyattes Coin Hangi Borsada
Kripto Para Kazanma
Tiktok Beğeni Hilesi
Bitcoin Oynama
Görüntülü Sohbet Parasız
Shibanomi Coin Hangi Borsada