This document provides an overview of Java Server Pages (JSP) technology. Some key points:
- JSP allows separation of work between web designers and developers by allowing HTML/CSS design and Java code to be placed in the same file.
- A JSP page is compiled into a servlet, so it can take advantage of servlet features like platform independence and database-driven applications.
- JSP pages use tags like <jsp:include> and <jsp:useBean> to include content and access JavaBeans. Scriptlets, expressions, declarations, and directives are also used.
- Implicit objects like request, response, out, and session are automatically available in JSP pages
Collections Framework is a unified architecture for managing collections, Main Parts of Collections Framework
1. Interfaces :- Core interfaces defining common functionality exhibited by collections
2. Implementations :- Concrete classes of the core interfaces providing data structures
3. Operations :- Methods that perform various operations on collections
Collections Framework is a unified architecture for managing collections, Main Parts of Collections Framework
1. Interfaces :- Core interfaces defining common functionality exhibited by collections
2. Implementations :- Concrete classes of the core interfaces providing data structures
3. Operations :- Methods that perform various operations on collections
Servlet is java class which extends the functionality of web server by dynamically generating web pages.
Servlet technology is used to create Dynamic web application. Servlet technology is robust and scalable. init() and service() methods are more important in life cycle of a servlet. doGet() and doPost() are methods used under service() method.
oops concept in java | object oriented programming in javaCPD INDIA
object oriented programming is a key concept for the development of application in windows as well as web based application environment. oops concept maps real world through its concept of classes, objects, inheritance, polymorphism which help in making a robust application.
Servlet is java class which extends the functionality of web server by dynamically generating web pages.
Servlet technology is used to create Dynamic web application. Servlet technology is robust and scalable. init() and service() methods are more important in life cycle of a servlet. doGet() and doPost() are methods used under service() method.
oops concept in java | object oriented programming in javaCPD INDIA
object oriented programming is a key concept for the development of application in windows as well as web based application environment. oops concept maps real world through its concept of classes, objects, inheritance, polymorphism which help in making a robust application.
This slide is about basics of java servlet and java server page.
A basic example of JSP using multiple directives.
Further information of setting up and using of Apache Tomcat server.
JavaScript, often abbreviated as JS, is a programming language and core techn...MathivananP4
JavaScript, often abbreviated as JS, is a programming language and core technology of the World Wide Web, alongside HTML and CSS. As of 2024, 98.9% of websites use JavaScript on the client side for webpage behavior, often incorporating third-party libraries.
JSP technology is used to create web application just like Servlet technology. It can be thought of as an extension to Servlet because it provides more accuracy.
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. Extension to Servlet, Easy to maintain, Fast Development: No need to recompile and redeploy, Less code than Servlet
Its an distributed enviornment for developing the enterprise application.We can develop multi-tier,three-tier or n-tier architecture using this.In this Java Server Pages and Servlet is the important things
Mumbai Academics is Mumbai’s first dedicated Professional Training Center for Training with Spoke and hub model with Multiple verticles . The strong foundation of Mumbai Academics is laid by highly skilled and trained Professionals, carrying mission to provide industry level input to the freshers and highly skilled and trained Software Professionals/other professional to IT companies.
The IP addresses used to identify systems on a TCP/IP network. The IP address is an absolute identifier of both the individual machine and the network on which it resides.
Every IP datagram packet transmitted over a TCP/IP network contains the IP addresses of the source system that generated it and the destination system for which it’s intended in its IP header.
A ‘Baseband’ Network is one in which the cable or other network medium can carry only a single signal at any one time.
A ‘Broadband’ network on the other hand can carry multiple signals simultaneously, (using a discrete part of the cables bandwidth for each signal.)
As an example of broadband network, consider the cable television service that you probably have in your home. Although only one cable runs at your TV, it supplies you with dozens of channels of programming at the same time.
Simple Network Management Protocol by vikas jagtapVikas Jagtap
NETWORK MANAGEMENT can be defined as monitoring, testing, configuring and trouble shooting network components to meet a set of requirements defined by an organization.
Set of requirements include the smooth, efficient operation of the network that provides the predefined quality of service for users
Knowledge discovery is a new field that combines several techniques from computer science and Artificial Intelligence.
Search for relations and global patterns in large databases.
It is defined as a non-trivial extract of implicit, unknown, and potential user information from databases.
ADVANCE DATABASE MANAGEMENT SYSTEM CONCEPTS & ARCHITECTURE by vikas jagtapVikas Jagtap
The data that indicates the earth location (latitude & longitude, or height & depth ) of these rendered objects is known as spatial data.
When the map is rendered, objects of this spatial data are used to project the location of the objects on 2-Dimentional piece of paper.
The spatial data management systems are designed to make the storage, retrieval, & manipulation of spatial data (i.e points, lines and polygons) easier and natural to users, such as GIS.
While typical databases can understand various numeric and character types of data, additional functionality needs to be added for databases to process spatial data types.
These are typically called geometry or feature.
Overview of Object-Oriented Concepts Characteristics by vikas jagtapVikas Jagtap
Object-oriented data base systems are proposed as alternative to relational systems and are aimed at application domains where complex objects play a central role.
The approach is heavily influenced by object-oriented programming languages and can be understood as an attempt to add DBMS functionality to a programming language environment
This ppt show how your age has being going from childhood to old age .what old man want to say to his child .
how parents play a vital role where there children are kids
Dubai is the most populous city and emirate in the United Arab Emirates, and the second largest emirate by territorial size after the capital, Abu Dhabi.
Area: 4,114 km²
Founded: June 9, 1833
Local time: Sunday 2:41 pm
Weather: 28°C, Wind W at 27 km/h, 48% Humidity
Population: 2.106 million (2013)
GDP per capita: 16,350.00 USD (2005)
Gross domestic product: 82.11 billion USD (2008)
Java applications cannot directly communicate with a database to submit data and retrieve the results of queries.
This is because a database can interpret only SQL statements and not Java language statements.
For this reason, you need a mechanism to translate Java statements into SQL statements.
The JDBC architecture provides the mechanism for this kind of translation.
The JDBC architecture can be classified into two layers :
JDBC application layer.
JDBC driver layer.
JDBC application layer : Signifies a Java application that uses the JDBC API to interact with the JDBC drivers. A JDBC driver is software that a Java application uses to access a database. The JDBC driver manager of JDBC API connects the Java application to the driver.
JDBC driver layer : Acts as an interface between a Java applications and a database. This layer contains a driver , such as a SQL server driver or an Oracle driver , which enables connectivity to a database.
A driver sends the request of a Java application to the database. After processing the request, the database sends the response back to the driver. The driver translates and sends the response to the JDBC API. The JDBC API forwards it to the Java application.
Server side programs can be written using different server-side technologies , such as Common Gateway Interface (CGI) , Active Server Pages (ASP) and Servlets.
CGI scripts are written in C , C++ or perl programming languages .
In case of an application server using CGI script to process client request , the server creates a separate instance of the CGI script to process the request.
As a result, the efficiency of the server is affected when there is large number of concurrent requests.
“Bluetooth wireless technology is an open specification for a low-cost, low-power, short-range radio technology for ad-hoc wireless communication of voice and data anywhere in the world.”
An Introduction to BLUETOOTH TECHNOLOGYVikas Jagtap
“Bluetooth wireless technology is an open specification for a low-cost, low-power, short-range radio technology for ad-hoc wireless communication of voice and data anywhere in the world.”
THREATS are possible attacks.
It includes
The spread of computer viruses
Infiltration and theft of data from external hackers
Engineered network overloads triggered by malicious mass e-mailing
Misuse of computer resources and confidential information by employees
Unauthorized financial transactions and other kinds of computer fraud conducted in the company's name
Electronic inspection of corporate computer data by outside parties
Damage from failure, fire, or natural disasters
The DNS name space is based on a domains, which exist in a hierarchical structure much like the directory tree in a file system.
A domain is the equivalent of a directory, in that it can contain either subdomains (subdirectories) or hosts (files), forming a structure called DNS tree.
The DNS name space function in the same way : administrators are assigned domain names and are then responsible for specifying host names to systems within that domain.
The result is that every computer on the Internet is uniquely identifiable by a DNS, name that consists of host name plus the names of all its parent domains, stretching up to the root of the DNS tree, separated by periods.
Each of the names between the periods can be up to 63 characters long, with a total length of 255 characters for a complete DNS name.
Domain and host names are not case sensitive, and can take any value except the null value.
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...Levi Shapiro
Letter from the Congress of the United States regarding Anti-Semitism sent June 3rd to MIT President Sally Kornbluth, MIT Corp Chair, Mark Gorenberg
Dear Dr. Kornbluth and Mr. Gorenberg,
The US House of Representatives is deeply concerned by ongoing and pervasive acts of antisemitic
harassment and intimidation at the Massachusetts Institute of Technology (MIT). Failing to act decisively to ensure a safe learning environment for all students would be a grave dereliction of your responsibilities as President of MIT and Chair of the MIT Corporation.
This Congress will not stand idly by and allow an environment hostile to Jewish students to persist. The House believes that your institution is in violation of Title VI of the Civil Rights Act, and the inability or
unwillingness to rectify this violation through action requires accountability.
Postsecondary education is a unique opportunity for students to learn and have their ideas and beliefs challenged. However, universities receiving hundreds of millions of federal funds annually have denied
students that opportunity and have been hijacked to become venues for the promotion of terrorism, antisemitic harassment and intimidation, unlawful encampments, and in some cases, assaults and riots.
The House of Representatives will not countenance the use of federal funds to indoctrinate students into hateful, antisemitic, anti-American supporters of terrorism. Investigations into campus antisemitism by the Committee on Education and the Workforce and the Committee on Ways and Means have been expanded into a Congress-wide probe across all relevant jurisdictions to address this national crisis. The undersigned Committees will conduct oversight into the use of federal funds at MIT and its learning environment under authorities granted to each Committee.
• The Committee on Education and the Workforce has been investigating your institution since December 7, 2023. The Committee has broad jurisdiction over postsecondary education, including its compliance with Title VI of the Civil Rights Act, campus safety concerns over disruptions to the learning environment, and the awarding of federal student aid under the Higher Education Act.
• The Committee on Oversight and Accountability is investigating the sources of funding and other support flowing to groups espousing pro-Hamas propaganda and engaged in antisemitic harassment and intimidation of students. The Committee on Oversight and Accountability is the principal oversight committee of the US House of Representatives and has broad authority to investigate “any matter” at “any time” under House Rule X.
• The Committee on Ways and Means has been investigating several universities since November 15, 2023, when the Committee held a hearing entitled From Ivory Towers to Dark Corners: Investigating the Nexus Between Antisemitism, Tax-Exempt Universities, and Terror Financing. The Committee followed the hearing with letters to those institutions on January 10, 202
Honest Reviews of Tim Han LMA Course Program.pptxtimhan337
Personal development courses are widely available today, with each one promising life-changing outcomes. Tim Han’s Life Mastery Achievers (LMA) Course has drawn a lot of interest. In addition to offering my frank assessment of Success Insider’s LMA Course, this piece examines the course’s effects via a variety of Tim Han LMA course reviews and Success Insider comments.
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
Francesca Gottschalk - How can education support child empowerment.pptxEduSkills OECD
Francesca Gottschalk from the OECD’s Centre for Educational Research and Innovation presents at the Ask an Expert Webinar: How can education support child empowerment?
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
Biological screening of herbal drugs: Introduction and Need for
Phyto-Pharmacological Screening, New Strategies for evaluating
Natural Products, In vitro evaluation techniques for Antioxidants, Antimicrobial and Anticancer drugs. In vivo evaluation techniques
for Anti-inflammatory, Antiulcer, Anticancer, Wound healing, Antidiabetic, Hepatoprotective, Cardio protective, Diuretics and
Antifertility, Toxicity studies as per OECD guidelines
2. JSP technology has facilitated the segregation of the work of
a Web designer and a Web developer.
A Web designer can design and formulate the layout for the
Web page by using HTML.
On the other hand, a Web developer working independently
can use java code and other JSP specific tags to code the
business logic.
The simultaneous construction of the static and dynamic
content facilitates development of quality applications with
increased productivity.
3. A JSP page , after compilation , generates a servlet and
therefore incorporates all servlet functionalities.
Servlets and JSP thus share common features, such as
platform independence , creation of database-driven Web
applications , and server side programming capabilities.
However , there are also some basic differences between
servlets and JSP :
4. Servlets tie up files (an HTML file for the static content and a
Java file for the dynamic contents) to independently handle the
static presentation logic and the dynamic business logic.
Due to this , a change made to any file requires recompilation
of the servlet.
JSP on the other hand allows Java to be embedded directly into
an HTML page by using tags.
The HTML content and the Java content can also be placed in
separate files.
Any changes made to HTML content is automatically compiled
and loaded onto the servlet
5. Servlet programming involves extensive coding.
Therefore, any change made to the code requires identification
of the static code content (for the designer) and dynamic code
content (for the developer) to facilitate incorporation of the
changes.
On the other hand, a JSP page, by virtue of the separate
placement of the static and dynamic content , facilitates both
Web developers and the Web designer to work independently.
6. JSP Life Cycle
When the client browser requests for a particular JSP page ,the
server in turns sends a request to the JSP engine.
A JSP engine is a part of a Web container , that compiles a JSP
page to a servlet.
The following figure represents the process of the flow of
events that occur after a client requests for a JSP page.
7. Request-Response Cycle for a JSP Page
Browser
Web
Container
( JSP
Engine)
Yes
No
Response
Response
Check to ensure if
the call to JSP is
first of its kind
Servlet
generation and
recompilation
Servlet
reloaded
Request
Response
8. The request-response cycle essentially comprises of two phases , namely
the translation phase and the request-processing phase.
The translation phase is implemented by the JSP engine and involves
generation of a servlet.
Internally , this results in the creation of a class file for the JSP page ,that
implements the servlet interface.
During the request-processing phase, the response is generated according
to the request specifications.
After the servlet is loaded for the first time, it remains active , processes all
the subsequent requests , and saves time that would otherwise be lost in
reloading a servlet at each time.
9. Once a JSP is translated to a servlet , the container invokes the
following life cycle methods on the servlet , that are defined in
the javax.servlet.jsp.JspPage interface:
1. jspInit() : This method is invoked at the time when the servlet
is initialized.
2. jspService() : This method is invoked when request for the JSP
page is received.
3. jspDestroy() : This method is invoked before the servlet is
removed from the service.
10. Assignment
Accept two numbers form the user form the AcceptInput.jsp
page .
Create Calculate.jsp to process the request and displays the
results
12. IncludePage.jsp
<html>
<body>
<h4> Today’s Date is :
<jsp:include page=“DatePage.jsp” flush=“true” /> </h4>
<%
out.println(“<h4> The ouput of the file DatePage.jsp is shown
above </h3>”);
%>
</body>
</html>
13. Classes of JSP API
JSP API is a set of classes and interfaces that you can use to
create a JSP pages.
These classes and interfaces are contained in the
javax.servlet.jsp package .
Some of the classes defined in the javax.servlet.jsp package
are :
1. ErrorData
2. JspWriter
3. PageContext
14. The ErrorData Class
The ErrorData class defines error information for error pages.
You need to set the value of the page directive , isErrorPage
to be true to indicate that a page is an error page.
The ErrorData class extends the java.lang.Object class .
Some of the methods defined in the ErrorData class that you
can use in a jsp page are :
15. 1. getRequestURL () :
-> Returns the requested URL in the form of a String.
2. getServletName () :
-> Returns the name of the servlet invoked in the form of a
String.
3. getStatusCode () :
-> Returns the status code of the error in the form of an interger.
4. getThrowable () :
-> Returns the Throwable exception that caused the error.
16. The JspWriter Class
The JspWriter class is used to write action and template data in
a JSP page.
The object of JspWriter class is referenced by the implicit
variable , out .
The JspWriter class extends the java.io.Writer class.
Some of the methos defined in the JspWriter class that you can
use in a JSP page are :
17. 1. clear() :
-> Clears the contents of the buffer. The clear() method throws an
IOException exception , if the buffer is already cleared.
2. close() :
-> Closes and flushes the stream
3. flush() :
->Flushes the buffer stream. The flush() method flushes all the buffers in a
chain of Writers and OutputStream.It throws java.io.IOException exception
if you make a call to the write () or flush() after closing the stream
18. 4. getBufferSize () :
-> Returns the size of the buffer used by the JspWriter
5. print() :
-> Prints a value of type boolean , interger ,character ,long integer , floating
point , double –precision floating –point number, an array of character ,
string , and object. The print() throws the java.io.IOException exception if
any error occurs while printing.
6. println() :
-> Prints a value of type boolean , interger ,character ,long integer , floating
point , double –precision floating –point number, an array of character ,
string , and object.This method writes a line separator string to terminate
the current line. The Println () throws the java.io.IOException exception if
any error occurs while printing
19. The PageContext Class
The PageContext class provides context information when the
JSP technology is used in the servlet environment.
The PageContext class extends the JspContext class.
A PageContext instances provides access to namespaces
associated with a JSP page.
Some of the methods defined in the PageContext class are :
20. 1. forward () :
-> Redirects the current servlet request and servlet response to another
page. This method accepts the URL of a target page as an argument.
2. getPage () :
->Returns the current value of the page object.
3. getRequest () :
-> Returns the current value of the request object. The return type of the
getRequest () is the servlet request.
4. getResponse():
-> Returns the current value of the response object. The return type of the
getResponse () method is the servlet response.
21. 5. getServletConfig ():
-> Returns the ServletConfig of the current page.
6. getServletContext () :
-> Returns the ServletContext of the current page.
7. getSession () :
->Returns the HttpSession for the current PageContext. The return type of
getSession () is HttpSession.
8. include () :
->Processes the current servlet request and the response specified in the
URL. The include () method asscepts two arguments, a URL path and the
flush value of boolean type
22. <html>
<head>
<title>My first JSP Page</title>
</head>
<body>
<%@page language=“java”%>
<% System.out.println(“Be in Peace”); %>
</body>
<html>
23. Using JSP tags
There are five main tags:
1. Declaration tag
2. Expression tag
3. Directive tag
4. Scriptlet tag
5. Action tag
24. Declaration tag (<%! %>)
This tag allows the developer to declare variables or methods.
Before the declaration you must have <%! And at the end of the declaration
the developer must have %>
Code placed in this must end in a semicolon(;).
Declarations do not generate output, so are used with JSP expressions or
scriptlets.
25. Example Of Declaration tag
<%!
private int counter = 0 ;
private String getAccount (int accountNo);
%>
26. Expression tag (<%= %>)
This tag allows the developer to embed any java expression
and is short for out.println().
A semicolon (;) does not appear at the end of the code inside
the tag.
28. Directive tag (<%@ directive…. %>)
A JSP directive gives special information about the jsp page , to the JSP
Engine.
There are three main types of directives:
1. page - processing information for this page
2. Include - files to be included
3. Tag library - tag library to be used in this page
29. Directive tag (Continue…..)
Directives do not produce any visible output when the page is
requested but change the way the JSP engine processes the
page.
For example , you can make session data unavailable to a
page by setting a page directive (session) to false.
30. 1. Page directive
This directive has 11 optional attributes that provides the JSP
Engine with special processing information.
The following table lists the 11 different attributes with a brief
description.
31. Language : Which language the file uses.
<%@ page language=“java” %>
Import : Import all the classes in a java package
into the current JSP page.This alllows the
JSP page to use other java classes.
The following packages are implicitly imported.
java.lang.*
javax.servlet.*
javax.servlet.jsp.*
javax.servlet.http.*
<%@ page import=“java.util.*” %>
32. session : Does the page make use of sessions.
By default all JSP pages have session data available.
Default is set to true.
buffer : Controls the use of the buffered output for the
JSP page. Default is 8 kb
<%@page buffer =“none” %>
autoFlush : Flush output buffer when full
<%@ page autoFlush=“true” %>
33. isThreadSafe : Can the generated Servlet deal
with multiple requests?
If true a new thread is started
so requests are handled simultaneously.
info : Developer uses info attribute to add
information/document for a page.
Typically used to add author , version,
copyright and date info
<%@ page info=“abc.com test page,copyright 2001.” %>
34. errorPage : Different page to deal with errors.
Must be URL to error page
<%@ page errorPage=“/error/error.jsp” %>
isErrorPage : This flag is set to true to make a JSP page
a special Error Page.
This page has access to the implicit object exception
35. 2.Include directive
Allows a JSP developer to include contents of a file inside
another.
Typically include files are used for navigation, tables , headers
and footers that are common to multiple pages.
36. Two examples of using include files:
This include the html from privacy.html found in the include
directory into the current jsp page.
<%@ include file = “include/privacy.html” %>
OR
To include a navigation menu (jsp file ) found in the current
directory.
<%@ include file = “navigation.jsp” %>
37. 3.Tag Lib directive
A tag lib is a collection of the custom tags that can be used by
the page.
<%@ taglib uri=“tag lib URI” prefix=“tag Prefix” %>
Custom tags were introduced in JSP 1.1 and allow JSP
developers to hide complex server side code from web
designers.
38. Scriptlet tag (<%... %>)
Between <% and %> tags , any valid Java Code is called a
Scriptlet.
This code can access any variable or bean declared.
39. For example , to print a variable .
<%
String message = “Be in Peace” ;
out.println(message);
%>
40. Action tag
There are three main roles of the action tags:
Enable the use of the server side Javabeans.
Transfer control between pages
browser independent support for applets
41. Javabeans
A Javabeans is a special type of the class that has a number of
methods.
The JSP page can call these methods so can leave most of the
code in these Javabeans.
For example, if you wanted to make a feedback form that
automatically sent out an email. By having a JSP page with a
form, when the visitors presses the submit button this sends
the details to a JavaBeans that sends out the emails. This way
there would be no code in the JSP page dealing with sending
emails.
42. To use a Javabean in a JSP page use the following syntax:
<jsp:usebean id=“ id” scope=“application” class=“…….” />
43. The following is a list of Javabean scopes:
page –
valid until page completes
request –
bean instance lasts for the client request.
session –
bean lasts for the client session
application –
bean instance created and lasts until application ends.
44. Dynamic JSP Include
You have seen how a file can be included into a JSP using an
include Directive:
<%@ include file = “include/privacy.html”%>
This is a useful for including common pages that are shared and
is included at compile time.
To include a page at run time you should use dynamic JSP
includes.
<jsp:include page=“URL” flush=“true”/>
45. <HTML>
<HEAD>
<TITLE> JSP Example </TITLE>
</HEAD>
<BODY>
JSP Example <BR>
<%!
String message = “Be in Peace”;
int counter = 0 ;
%>
Todays Message is
<%=message%> <Br>
Counter is <%=counter%>
</BODY>
</HTML>
46. Implicit Objects
There are several objects that are automatically available
in JSP called implicit objects.
47. Variable Of type
request javax.servlet.http.httpServletRequest
response javax.servlet.http.httpServletResponse
out javax.servlet.jsp.JspWriter
session javax.servlet.http.HttpSession
pagecontent javax.servlet.jsp.PageContext
application javax.servlet.http.ServletContext
config javax.servlet.http.ServletConfig
page javax.lang.Object
exception java.lang.Throwable
48. page object -
Represents the JSP page and is used to call any
methods defined by the servlet class.
config object -
Stores the Servlet configuration data.
49. request object
Access to information associated with a request. This
object is normally used in looking up parameter values and
cookies.
<% String str = request.getParameter(“uname”); %>
50. Session Tracking in JSP (Session Object)
Cookies – a small text file stored on the clients machine.
Cookie can be disables in the browser settings so are not
always available.
URL rewriting – store session information in the URL. Works
when cookies are not supported but can make bookmarking of
web pages a problem because they have session specific
information at the end of a URL.
51. Hidden form fields - HTML hidden edit boxes such as
<input type = “hidden” name=“user” value=“ ---”>
Session objects – JSP Implicit Object
52. A session object uses a key / value combination to store
information.
To retrieve information from a session:
session.getValue(“msg”)
The return type of the method getValue is Object , so you will
need to typecast to get the reuired value. If there is not a
session key with that name , null is returned.
53. To set a session key with a value,
session.putValue (“msg” , val)
54. JSP comments<%-- JSP comment--%>
JSP comments are similar to HTML comments
<!– HTML comment -- >
except JSP comments are never sent to the user’s browser.
HTML comments are visible in the page source.
55. <html>
<head>
<title>
HTML and JSP Comments
</title>
</head>
<body>
<h2> Comments </h2>
<!— This HTML Comment-visible in the page source -->
<%-- This JSP comment-Not visible in the page source -- %>
</body>
</html>
56. Error pages
Eventually there will come a time when sometime unexpected
happens.
In Java terms, this is when an exception gets thrown.
JSP can handle these situations so when an exception is
thrown , a default error page is sent to the browser.
So what makes an error page different from other JSP pages?
57. One of the first lines in an error page must be the page directive
isErrorPage=“true”
Inside your default error page (errorPage.jsp), above
the<HTML> tag type:
<%@ page isErrorPage=“true” import=“java.util.*” %>
<HTML>
<BODY>
Error Occurred
<%= exception.toString() %>
</Body>
<HTML>
58. Our error page also uses the exception object and the
toString() method to display a brief description of the error.
To use a specific error page in your JSP pages, again above
the <HTML> tag type:
<%@ page errorPage=“errorPage.jsp”%>
<HTML>
………..
</HTML>
This code will go to errorPage.jsp if an error occurs.
Even after an error, the HTTP session remains available.
61. In JSP 1.2 , it is not necessary that the errorPage value be a
JSP page.
It can also be a static file , such as an HTML page:
<%@ page errorPage = “errorHandler.html” %>
62. The Need for JSP
• With servlets, it is easy to
– Read form data
– Read HTTP request headers
– Set HTTP status codes and response headers
– Use cookies and session tracking
– Share data among servlets
– Remember data between requests
– Get fun, high-paying jobs
• But, it sure is a pain to
– Use those println statements to generate HTML
– Maintain that HTML
63. The JSP Framework
• Idea:
– Use regular HTML for most of page
– Mark servlet code with special tags
– Entire JSP page gets translated into a servlet (once), and servlet is
what actually gets invoked (for each request)
• Example:
<HTML>
<HEAD>
<TITLE>Order Confirmation</TITLE>
</HEAD>
<BODY>
<H2>Order Confirmation</H2>
Thanks for ordering <I> <%= request.getParameter("title") %> </I> !
</BODY>
</HTML>
64. Benefits of JSP
– Write HTML.
– Read and maintain the HTML.
– Use standard HTML tools such as Macromedia DreamWeaver or Adobe
GoLive.
– Have different members of your team do the HTML layout than do the
Java programming.
– Separate the (Java) code that creates the content from the (HTML)
code that presents it.
65. Advantages of JSP Over Competing Technologies
• Versus ASP or ColdFusion
– Better language for dynamic part
– Portable to multiple servers and operating systems
• Versus PHP
– Better language for dynamic part
– Better tool support
• Versus pure servlets
– More convenient to create HTML
– Can use standard tools (e.g., DreamWeaver)
– Divide and conquer
– JSP programmers still need to know servlet programming
66. • Versus Velocity or WebMacro
– Standard
• Versus client-side JavaScript (in browser)
– Capabilities mostly do not overlap with JSP, but
• You control server, not client
• Richer language
• Versus server-side JavaScript (e.g., LiveWire, BroadVision)
– Richer language
• Versus static HTML
– Dynamic features
– Adding dynamic features no longer "all or nothing" decision
67. Setting Up Your Environment
• Set your CLASSPATH : Not.
• Compile your code : Not.
• Use packages to avoid name conflicts : Not.
• Put JSP page in special directory: Not.
• Use special URLs to invoke JSP page: Not.
– Use same URLs as for HTML pages (except for file extensions)
69. <HTML>
<BODY>
<%
// This is a scriptlet. Notice that the "date"
// variable we declare here is available in the
// embedded expression later on.
System.out.println( "Evaluating date now“ );
java.util.Date date = new java.util.Date();
%>
Hello! The time is now :
<%= date %>
</BODY>
</HTML>
70. <HTML>
<BODY>
<%
// This scriptlet declares and initializes "date"
System.out.println( "Evaluating date now" );
java.util.Date date = new java.util.Date();
%>
Hello! The time is now
<%
// This scriptlet generates HTML output
out.println( String.valueOf( date ));
%>
</BODY>
</HTML>
71. <HTML>
<BODY>
<%
// This scriptlet declares and initializes "date"
System.out.println( "Evaluating date now" );
java.util.Date date = new java.util.Date();
%>
Hello! The time is now
<%
out.println( date );
out.println( "<BR>Your machine's address is " );
out.println( request.getRemoteHost() );
%>
</BODY>
</HTML>
72. <TABLE BORDER=2>
<%
for ( int i = 0; i < n; i++ )
{
%>
<TR>
<TD> Number </TD>
<TD> <%= i+1 %> </TD>
</TR>
<%
}
%>
</TABLE>
73. <%
if ( hello )
{
%>
<P> Hello, world
<%
}
else
{
%>
<P>Goodbye, world
<%
}
%>
74. JSP Directives
<%@ page import="java.util.*" %>
<HTML>
<BODY>
<%
System.out.println( "Evaluating date now" );
Date date = new Date();
%>
Hello! The time is now
<%= date %>
</BODY>
</HTML>
The first line in the above example is called a "directive".
A JSP "directive" starts with <%@ characters.
<%@ page import= "java.util.*, java.text.*" %>
75. The include directive is used to physically include the contents of another
file.
The included file can be HTML or JSP or anything else -- the result is as if
the original JSP file actually contained the included text.
<HTML>
<BODY>
Going to include hello.jsp...<BR>
<%@ include file="hello.jsp" %>
</BODY>
</HTML>
76. JSP Declarations
<%@ page import="java.util.*" %>
<HTML>
<BODY>
<%!
Date theDate = new Date();
Date getDate()
{
System.out.println( "In getDate() method“);
return theDate;
}
%>
Hello! The time is now
<%= getDate() %>
</BODY>
</HTML>
85. Answers
1. All primitive literals are fine.
2. No! The semicolon can’t be here.
3. String literal is fine.
4. Yes, the method returns a double.
5. No! you can’t have a variable declaration here.
6. Yes , because the new String array is an object , and ANY object can be
sent to a println() statement.
7. No! The arithmetic is fine , but there’s a space between the % and the =.
It can’t be <% = , it must be <%=
8. Sure , this resolves to a boolean, so it prints ‘true’.
9. Primitive literals are fine
10. No problem. This is just like the String [] …. It prints the result of the
object’s toString() method.
86. Will it compile? Will it Work?
<html>
<body>
<%
int count = 0;
%>
The page count is :
<%= ++count %>
</body>
</html>
If it compiles see the O/P
87. What Really happens to your JSP code?
This JSP:
<html>
<body>
<% int count = 0; %>
The Page count is now :
<%= ++count %>
</body>
</html>
88. Becomes this servlet:
public class basicCounter_jsp extends SomeSpecialHttpServlet
{
public void _jspservice(HttpServletRequest req,HttpServletResponse resp)
throws java.io.IOException , ServletException
{
PrintWriter out = response.getWriter();
response.setContentType(“text/html”);
out.write(“<html><body>”);
int count = 0;
out.write(“The page count is now:”);
out.print(++count);
out.write(“</body></html>”);
}
}
89. Assignment
John Barrett the Chief Technology Officer has entrusted the development
team with the task of creating an application that validates id and
password of every customer before they can access their account datails.
The customer id has to be in a numeric form.
He also wants that an error message should be displayed to the
customer, if the entered customer id or password is incorrect.
Before the changes can be made to the entire application , John wants to
test this functionality be making a sample application for a specific
customer .
Larry Williams , the programmer has been assigned the task of
implementing this functionality.
Larry decides to use JSP for developing this application