Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Learn JSP in 24 Hours
Learn JSP in 24 Hours
Learn JSP in 24 Hours
Ebook259 pages57 minutes

Learn JSP in 24 Hours

Rating: 0 out of 5 stars

()

Read preview

About this ebook

Java Server Pages or JSP technology is used to develop dynamic Java-based web applications. Various frameworks like JavaServer Faces, Struts 2, or Spring MVC are based on JSP. To quickly switch on to this technology and to reduce JSP learning time this e-book is designed.


The step by step explanation of code and images in this book, will enable you to get a greater level of understanding on how JSP works? The book tried to explain some JSP core subject like JSTL tags, expressions, EL, etc. from grass root level. This edition has demonstrated examples on how to write template text in client side languages like JavaScript, HTML, CSS, and so on. To make JSP more interactive, real-time code execution option is also given. While for beginners key concepts of JSP is made easy to grasp.


With a lot of example and coverage given, this book can be a learning guide for J2EE exams. It will answer all your JSP queries. The users will not struggle anymore with error handling, implementing caching strategies or re-using code across pages after going through this book. The book is small but loaded with vital information on JSP.


Table of content


Chapter 1: Introduction


What is JSP?


Why use JSP?


Advantages of JSP


Chapter 2: JSP Life Cycle


Chapter 3: Install JSP with Jboss Server & Java


Install Java


Install Jboss Server


Installation Testing


Your First JSP


Chapter 4: Elements


JSP Declaration


JSP Syntax


JSP Expression


JSP Comments


Creating a simple JSP Page


How to run simple JSP Page


Directory Structure of JSP


Chapter 5: Actions


Directives


Page directive


Implicit objects


Action


Chapter 6: Expression Language (EL)


Syntax of Expression Language (EL)


If-else


Switch


For loop


While loop


Operators


Chapter 7: Exception Handling


JSP Exception


Checked Exceptions


Runtime Exceptions


Error Exception


Chapter 8: MVC


MVC architecture


Example of MVC architecture


Chapter 9: Tag Library


What is JSTL


JSTL Core


JSP Custom Tags


Chapter 10: Action - File Upload, JSP Filter, Client Request, Server Response, Cookies Handling, Date Handling


Client Request


Server Response


HTTP Status Codes


Form Processing


Filter


Cookies Handling


File Upload


Date Handling


Chapter 11: Database connection


Create Table


Create Records


JSP Operations: Insert, Update, Delete, Select


Chapter 12: JSP Example


Registration form


Login and Logout form


Uploading and download file


Chapter 13: Debug JSP Using Java Logger, Println statements & Debugging tools


JSP Debugging Methods


Using println statements


Using Java Logger


Using debugging tools

LanguageEnglish
PublisherPublishdrive
Release dateOct 30, 2021
Learn JSP in 24 Hours

Read more from Alex Nordeen

Related to Learn JSP in 24 Hours

Related ebooks

Internet & Web For You

View More

Related articles

Reviews for Learn JSP in 24 Hours

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Learn JSP in 24 Hours - Alex Nordeen

    Chapter 1: Introduction

    JSP is used to create a web application. It focuses more on the presentation part of the application. It also separates the presentation layer with the business layer in MVC (which will be learnt in more detail in MVC section).

    JSP stands for Java Server Pages.

    It is a technology which helps to create dynamic pages using HTML, XML.

    It uses Java as a programming language into JSP.

    What is JSP?

    Java Server Pages (JSP) is a technology which is used to develop web pages by inserting java code into the HTML pages by making special JSP tags. The JSP tags which allow java code to be included into it are <% ----java code----%>.

    It can consist of either HTML or XML (combination of both is also possible) with JSP actions and commands.

    It can be used as HTML page, which can be used in forms and registration pages with the dynamic content into it.

    Dynamic content includes some fields like dropdown, checkboxes, etc. whose value will be fetched from the database.

    This can also be used to access JavaBeans objects.

    We can share information across pages using request and response objects.

    JSP can be used for separation of the view layer with the business logic in the web application.

    Why use JSP?

    In Java server pages JSP, the execution is much faster compared to other dynamic languages.

    It is much better than Common Gateway Interface (CGI).

    Java server pages JSP are always compiled before its processed by the server as it reduces the effort of the server to create process.

    Java server pages JSP are built over Java Servlets API. Hence, it has access to all Java APIs, even it has access to JNDI, JDBC EJB and other components of java.

    JSP are used in MVC architecture (which will be covered in MVC architecture topic) as view layer.

    The request is processed by a view layer which is JSP and then to servlet layer which is java servlet and then finally to a model layer class which interacts with the database.

    JSP is an important part of Java EE, which is a platform for enterprise level applications.

    Advantages of JSP

    The advantage of JSP is that the programming language used is JAVA, which is a dynamic language and easily portable to other operating systems.

    It is very much convenient to modify the regular HTML. We can write the servlet code into the JSP.

    It is only intended for simple inclusions which can use form data and make connections.

    JSP can also include the database connections into it. It can contain all type of java objects.

    It is very easy to maintain

    Performance and scalability of JSP are very good because JSP allows embedding of dynamic elements in HTML pages.

    As it is built on Java technology, hence it is platform independent and not depending on any operating systems.

    Also, it includes the feature of multithreading of java into it.

    We can also make use of exception handling of java into JSP.

    It enables to separate presentation layer with the business logic layer in the web application.

    It is easy for developers to show as well as process the information.

    Summary:

    In this tutorial, we have learnt about JSP which is Java server pages

    JSP pages are used as underlying technology is Java which makes it platform independent. It can be done within the HTML and XML pages

    It is very easy and convenient to use JSP over the HTML pages.

    Chapter 2: JSP Life Cycle

    A JSP Page needs to be converted into servlet first in order to process the service requests. Translation of JSP Page into servlet is termed as the life cycle of JSP. It starts with the creation of JSP and ends with the disintegration of that.

    In this tutorial, you will learn-

    Different phases of JSP Life Cycle.

    When the browser asks for a JSP, JSP engine first checks whether it needs to compile the page. If the JSP is last compiled or the recent modification is done in JSP, then the JSP engine compiles the page.

    Compilation process of JSP page involves three steps:

    Parsing of JSP

    Turning JSP into servlet

    Compiling the servlet

    JSP Lifecycle is depicted in the below diagram.

    Following steps explain the JSP life cycle:

    Translation of JSP page

    Compilation of JSP page(Compilation of JSP page into _jsp.class)

    Classloading (_jsp.java is converted to class file _jsp.class)

    Instantiation(Object of generated servlet is created)

    Initialisation(_jspinit() method is invoked by container)

    Request Processing(_jspservice() method is invoked by the container)

    Destroy (_jspDestroy() method invoked by the container)

    Let us have more detailed summary on the above points:

    Translation of the JSP Page:

    A Java servlet file is generated from a JSP source file. This is the first step of JSP life cycle. In translation phase, container validates the syntactic correctness of JSP page and tag files.

    The JSP container interprets the standard directives and actions, and the custom actions referencing tag libraries (they are all part of JSP page and will be discussed in the later section) used in this JSP page.

    In the above pictorial description, demo.jsp is translated to demo_jsp.java in the first step

    Let's take an example of demo.jsp as shown below:

    Demo.jsp

    Demo JSP

    <%

    int demovar=0;%>

    Counc is:

    <% Out.printIn(demovar++)

     

     

    Code Explanation for Demo.jsp

    Code Line 1: html start tag

    Code Line 2: Head tag

    Code Line 3 - 4: Title Tag i.e. Demo JSP and closing head tag

    Code Line 5,6: Scriptlet tag wherein initializing the variable demo

    Code Line 7 - 8: In body tag, a text to be printed in the output (Count is: )

    Code Line 9: Scriplet tag where trying to print the variable demovar with incremented value

    Code Line 10-11: Body and HTML tags closed

    Demo JSP Page is converted into demo_jsp servlet in the below code.

    Public class demp_jsp extends HttpServlet{

    Public void _]sp3ervice(HttpServletRequest request, HttpServletResponse response) Throws IOException, ServletException

    {

    PrintWriter out = response.getKriter<);

    response.3etContentType(text/html);

    out .write <) ;

    int demovar=0;

    out.write(Count is:);

    out.print(demovar++);

    out .write () ;

    }

    }

    Code explanation for Demo_jsp.java

    Code Line 1: Servlet class demo_jsp is extending parent class HttpServlet

    Code Line 2,3: Overriding the service method of jsp i.e. _jspservice which has HttpServletRequest and HttpServletResponse objects as its parameters

    Code Line 4: Opening method

    Code Line 5: Calling the method getWriter() of response object to get PrintWriterobject (prints formatted representation of objects to text output stream)

    Code Line 6: Calling setContentType method of response object to set the content type

    Code Line 7: Using write () method of PrintWriter object trying to parse html

    Code Line 8: Initializing demovar variable to 0

    Code Line 9: Calling write() method of PrintWriter object to parse the text

    Code Line 10: Calling print() method of PrintWriter object to increment the variable demovar from 0+1=1.Hence, the output will be 1

    Code Line 11: Using write() method of PrintWriter object trying to parse html

    Output:

    JSP Life Cycle

    Here you can see that in the screenshot theOutput is 1 because demovar is initialized to 0 and then incremented to 0+1=1

    In the above example,

    demo.jsp, is a JSP where one variable is initialized and incremented. This JSP is converted to the servlet (demo_jsp.class ) wherein the JSP engine loads the JSP Page and converts to servlet content.

    When the conversion happens all template text is converted to println() statements and all JSP

    Enjoying the preview?
    Page 1 of 1