Learn JSP in 24 Hours
By Alex Nordeen
()
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
Read more from Alex Nordeen
Learn SAP MM in 24 Hours Rating: 0 out of 5 stars0 ratingsLearn SAP Basis in 24 Hours Rating: 5 out of 5 stars5/5Learn SAP HR in 24 Hours Rating: 5 out of 5 stars5/5Learn HANA in 24 Hours Rating: 5 out of 5 stars5/5Learn SAP SD in 24 Hours Rating: 0 out of 5 stars0 ratingsLinux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Python: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5Learn MongoDB in 24 Hours Rating: 5 out of 5 stars5/5Learn PMP in 24 Hours Rating: 0 out of 5 stars0 ratingsLearn Software Testing in 24 Hours Rating: 0 out of 5 stars0 ratingsLearn SQL in 24 Hours Rating: 5 out of 5 stars5/5C++ Learn in 24 Hours Rating: 0 out of 5 stars0 ratingsLearn SAP BI in 24 Hours Rating: 3 out of 5 stars3/5Learn JavaScript in 24 Hours Rating: 3 out of 5 stars3/5Learn Data Warehousing in 24 Hours Rating: 0 out of 5 stars0 ratingsLearn Operating System in 24 Hours Rating: 0 out of 5 stars0 ratingsBusiness Analysis : Learn in 24 Hours Rating: 0 out of 5 stars0 ratingsLearn Excel in 24 Hours Rating: 4 out of 5 stars4/5Learn PHP in 24 Hours Rating: 0 out of 5 stars0 ratingsLearn Selenium in 24 Hours Rating: 0 out of 5 stars0 ratingsHacking : Guide to Computer Hacking and Penetration Testing Rating: 5 out of 5 stars5/5Learn SQLite in 24 Hours Rating: 0 out of 5 stars0 ratingsLearn R Programming in 24 Hours Rating: 0 out of 5 stars0 ratingsC# for Beginners: Learn in 24 Hours Rating: 0 out of 5 stars0 ratingsLearn Cassandra in 24 Hours Rating: 0 out of 5 stars0 ratingsLearn AngularJS in 24 Hours Rating: 0 out of 5 stars0 ratingsLearn Hive in 24 Hours Rating: 0 out of 5 stars0 ratingsLearn DBMS in 24 Hours Rating: 0 out of 5 stars0 ratingsLearn Design and Analysis of Algorithms in 24 Hours Rating: 0 out of 5 stars0 ratingsLearn VBScript in 24 Hours Rating: 0 out of 5 stars0 ratings
Related to Learn JSP in 24 Hours
Related ebooks
Practical Java Programming for IoT, AI, and Blockchain Rating: 0 out of 5 stars0 ratings100 Recipes for Programming Java Rating: 5 out of 5 stars5/5Spring MVC Cookbook Rating: 0 out of 5 stars0 ratingsJavaScript: Beginner's Guide to Programming Code with JavaScript: JavaScript Computer Programming Rating: 0 out of 5 stars0 ratingsLearn ASP.NET Core MVC - Be Ready Next Week Using Visual Studio 2017 Rating: 5 out of 5 stars5/5Spring Boot and Single-Page Applications: Securing Your API with a Single-Page Application Frontend - Second Edition Rating: 0 out of 5 stars0 ratingsPractical Java 8: Lambdas, Streams and new resources Rating: 5 out of 5 stars5/5Java Programming: 24-Hour Trainer Rating: 0 out of 5 stars0 ratingsJavascript Concepts: 1St Edition Rating: 0 out of 5 stars0 ratings120 Advanced JavaScript Interview Questions Rating: 0 out of 5 stars0 ratingsJava: Tips and Tricks to Programming Code with Java: Java Computer Programming, #2 Rating: 0 out of 5 stars0 ratingsJava Multithreading Interview Questions And Answers Rating: 0 out of 5 stars0 ratingsASP.NET For Beginners: The Simple Guide to Learning ASP.NET Web Programming Fast! Rating: 0 out of 5 stars0 ratingsMastering JavaScript: The Complete Guide to JavaScript Mastery Rating: 5 out of 5 stars5/5Java Programming Rating: 0 out of 5 stars0 ratingsIan Talks JavaScript Libraries and Frameworks A-Z: WebDevAtoZ, #4 Rating: 0 out of 5 stars0 ratingsQuick JavaScript Learning In Just 3 Days: Fast-Track Learning Course Rating: 0 out of 5 stars0 ratingsJavaScript Patterns JumpStart Guide (Clean up your JavaScript Code) Rating: 4 out of 5 stars4/5Java / J2EE Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsLearn NodeJS in 1 Day: Complete Node JS Guide with Examples Rating: 3 out of 5 stars3/5Mastering JavaServer Faces 2.2 Rating: 0 out of 5 stars0 ratings50 Recipes for Programming Node.js Rating: 3 out of 5 stars3/5Wb Development full course : from zero to web hero Rating: 0 out of 5 stars0 ratingsJAVA for Beginner's Crash Course: Java for Beginners Guide to Program Java, jQuery, & Java Programming Rating: 4 out of 5 stars4/5Java Design Patterns for Automation and Performance : Convenient Practical Reliable Rating: 0 out of 5 stars0 ratingsThe Java Workshop: Learn object-oriented programming and kickstart your career in software development Rating: 0 out of 5 stars0 ratings
Internet & Web For You
Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Six Figure Blogging Blueprint Rating: 5 out of 5 stars5/5How to Disappear and Live Off the Grid: A CIA Insider's Guide Rating: 0 out of 5 stars0 ratingsHow To Start A Profitable Authority Blog In Under One Hour Rating: 5 out of 5 stars5/5Everybody Lies: Big Data, New Data, and What the Internet Can Tell Us About Who We Really Are Rating: 4 out of 5 stars4/5No Place to Hide: Edward Snowden, the NSA, and the U.S. Surveillance State Rating: 4 out of 5 stars4/5Coding For Dummies Rating: 5 out of 5 stars5/5The $1,000,000 Web Designer Guide: A Practical Guide for Wealth and Freedom as an Online Freelancer Rating: 4 out of 5 stars4/5The Hacker Crackdown: Law and Disorder on the Electronic Frontier Rating: 4 out of 5 stars4/5The Beginner's Affiliate Marketing Blueprint Rating: 4 out of 5 stars4/5The Gothic Novel Collection Rating: 5 out of 5 stars5/5JavaScript All-in-One For Dummies Rating: 5 out of 5 stars5/5Tor and the Dark Art of Anonymity Rating: 5 out of 5 stars5/5How to Be Invisible: Protect Your Home, Your Children, Your Assets, and Your Life Rating: 4 out of 5 stars4/5Social Engineering: The Science of Human Hacking Rating: 3 out of 5 stars3/5Coding with AI For Dummies Rating: 0 out of 5 stars0 ratingsGrokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Python QuickStart Guide: The Simplified Beginner's Guide to Python Programming Using Hands-On Projects and Real-World Applications Rating: 0 out of 5 stars0 ratingsHTML in 30 Pages Rating: 5 out of 5 stars5/5Beginner's Guide To Starting An Etsy Print-On-Demand Shop Rating: 0 out of 5 stars0 ratingsCybersecurity For Dummies Rating: 5 out of 5 stars5/5Ultimate guide for being anonymous: Avoiding prison time for fun and profit Rating: 5 out of 5 stars5/5The Digital Marketing Handbook: A Step-By-Step Guide to Creating Websites That Sell Rating: 5 out of 5 stars5/5500 Writing Prompts for Fiction, Journaling, Blogging, and Creative Writing: Writing Prompts, #1 Rating: 0 out of 5 stars0 ratingsSurveillance and Surveillance Detection: A CIA Insider's Guide Rating: 3 out of 5 stars3/5Cybersecurity All-in-One For Dummies Rating: 0 out of 5 stars0 ratingsPodcasting For Dummies Rating: 4 out of 5 stars4/5
Reviews for Learn JSP in 24 Hours
0 ratings0 reviews
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
<%
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 CycleHere 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