This document provides information about Server Side Includes (SSI) and how they allow embedding instructions inside HTML documents to add dynamic content. SSI uses special tags and the file must have a .shtml extension. It discusses how servlets can also be used to add dynamic content. The document then covers Server Side Include tags and provides an example. It also discusses cookies, how they work, and some cookie methods. Finally, it summarizes what filters are, their benefits, types, how to program them, and how they are registered and mapped to servlets.
GAC Java Presentation_Server Side Include_Cookies_Filters 2022.ppt
1. GOVERNMENT ARTS COLLEGE
Melur, Madurai
By
Mr. V. Veeranan
Roll No: P22PCS123
I M.Sc. Computer Science
Topic: Server Side Include
(Cookies and Filters)
PG. Department of Computer Science
ADVANCED JAVA PROGRAMMING
2. Server Side Includes (SSI)
Embed instructions to the Server
Inside an HTML document
HTML tag Language
A special file -> .shtml
SHTML -> the web server
Servlets
To add small of dynamic content
Otherwise static HTML pages
3. Server-side Includes(SSI)
Server-Side Includes (SSI) give you the ability to embed
instructions to the server inside an HTML document.
The instructions are given using extensions to the HTML tag
language. A special file extension,
. shtml, signals the server that the document contains SSI directives.
SHTML is a file extension that lets the web server know the file
should be processed as using Server Side Includes(SSI)
Servlets are not confined to handling entire requests. Some web
servers allow servlets to add small amounts of dynamic content to
otherwise static HTML pages.
4. Server Side Include Tag
A page that uses the advertisement servlet is written just like a normal
HTML page, except that it contains one or more <SERVILET> tags
and is saved with the .shtml extension.
• The <SERVIET> tag is similar to the <APPLET> tag, which loads an
applet within a page. When a client requests a .shtml page, the server
finds all of the <SERVLET> tags in the text and replaces them with the
output from the appropriate servlets.
• When you use a <SERVLET> tag, you must include a CODE parameter
that identifies the servlet to be loaded. This can be a class name or a
servlet allas set up within the server. On some servers, you can specify
an optional CODEBASE parameter that loads the servlet code from a
remote location.
5. Server Side Include
• Any additional parameters are treated as servlet initialization
parameters. Each <SERVLET> tag must be matched by a
closing</SERVLET> tag.
• Between the opening and closing tags, you can include as many
<PARAM> tags as necessary, where you specify NAME and
VALUE attributes for each one.
• The servlet can them access these parameters with getParameter().
6. Example (Time.shtml)
<HTML>
<HEAD> <TITLE> Times1</TITLE></HEAD>
<BODY>
The current time here is:
<SERVLET CODE=CurrentTime>
</SERVLET>
<p>
The current time in London is:
<SERVLET CODE
7. Cookies
• Cookies is a small text file containing client information sent by a
web server to a browser that can later be read back from the
browser.
• When a browser receives a cookie, it saves the cookie and there after
sends the cookie back to the server each time it accesses a page on
the server, subject to certain rules.
• Since cookie’s value can uniquely identify a client, cookies are often
used for session tracking.
• The browser is expected to support 20 cookies for each Web server,
300 cookies total any may limit cookie size to 4kb each.
9. Working with Cookies
Create Cookie Class Constructor
public Cookie(String name, String Value())
Create Cookie, Send -> Browser
HttpServletResponce.addCookie(Cookie Cokie)
Servlet -> Request
HttpServletRequest.getCookies()
10. Cookie Methods
Specifies a Comment
public void setComment(java.lang.String purpose)
Comment using describing
public java.lang.String getComment()
Specifies the Domain name
public void setDomain(java.lang.String pattern)
The Maximum age -> Cookie
public void setMaxAge(int expiry)
Positive Vallue -> Negative value -> Zero Value
Return the Maximum age -> Cookie
public int setMaxAge()
Set of URIs -> Client
public void setPath(java.lang.String.url)
11. Cookie Methods
Returns the Paths
public java.lang.String.getPath()
Indicates to the Browser
public vaid setSecure(boolean flag)
Returns true if -> Browser -> Sending
public Boollean getSecure()
12. Filters
Filter is a component which dynamically intercepts requests
and responses to transform or use the information contained
in the requests or response,
Filters typically do not themselves create responses but
provide universal functions that can be “attached” to any
type of servlet or JSP page.
A filter is a program that runs on the server before the servlet
with which it is associated.
13. Benefits of Filters
Filters encapsulates common behaviour in a modular and
reusable manner.
It separates high-level access decisions from presentation
code.
It applies wholesale changes to many different resources.
14. Types/Components of Filters
Filters can perform many different types of functions. Based on
their functionalities following are the filters
Authentication: Blocking requests based on user identity.
Logging and auditing: Tracking users of a web application.
Image conversion: Scaling maps and so on.
Localization: Targeting the request and response to particular
locale.
XSL/T Transformations of XML Content: Targeting web
application responses to more than one type of client.
15. Programming a Filter
Create a class that implement the filter interface
Put the filtering behaviour in the doFilter method
Call the doFilter Method of the FilterChain object
Register the filter with the appropriate servlets and JSP pages
Disable the invoker servlet.
16. Filter Element in web.xml
Icon
Filter-name
Display-name
Description
Filter-class
Init-param
Filter-Mapping Element
Filter-name
url-pattern
Servlet-name
17. Process of Registering
Filter with Servlet
One filter can be associated with more than one servlet.
More than one filter can be mapped to a servlet.
A filter can be mapped to all the servlet using an “*”.
The filter, filter-mapping, serdfsdvlet and servlet-mapping
element must appear in the web application deployment
descriptor in that order.
18. Filter Life Cycle
Methods Controlling life cycle of a filter are as follows
init()
doFilter()
destroy()
Three methods of Filter interface makes up the life cycle of a
filter.
public void init(FilterConfig config) throws ServletException
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws ServletException, IOException
public void destroy()