Servlet
Servlet
Path setup:-
Right click on pom.xml run as maven install go to console check for
build success.
Right click on project maven update project check box click force
update .
Assignment:-
person.jsp
Person details
name : aaa
age : 18
gender : male
email: [email protected]
SERVLET & JSP
Web Server:-
Web server is a software which can receive the request from client and it
can serve some web content to the client as response.
Generally web server only can handle static resources like html , css images
etc.
Web server is limited to client server communication.
Example of web server Apache http server , micro soft iis etc.
Application server:-
Print writer:-
Request Dispatcher:-
forward ( ):-
forward ( ) has request dispatches will accept request and response object
as argument.
Forward( ) will transfer entire controll from one resource to another
resource so response generated by current page only display on web
browser.
include ( ):-
Web-Application:-
Client:-
In client server architecture client is nothing but a web browser.
In a computer we can have more than one client.
Client is responsible to send request and to receive response.
Ex:-chrome , internet explorer , safari , fire fox , opera min ……..etc.
Server:-
Static Response:-
the response which does not changes from user to user is known as static
response.
Dynamic Response:-
SERVLET & JSP
Generic Servlet:-
Http Servlet:-
It is a abstract class without any abstract methods.
It is present in javax.servlet.http package.
It is a direct child of generic servlet class and indirect child of servlet
interface.
http servlet class contains the methods which is specific to http method like
get , post……..etc.
Servlet:-
Servlet ( I ) 5 methods
Servlet interface:-
SERVLET & JSP
URL re-writing:-
In url re-writing technique we have to transfer the data through url in the
form of query String.
url re writing is suitable for get request.
In url re writing data will be attached to url in the form of key and value
pairs.
Http session:-
By using request reference we can invoke get session method which will
return implementation class object of http session.
The type of http session object is singleton.
By using set attribute method of http session we can add the data into http
session object in key and value pairs.
Set attribute method will accept two arguments as argument one we have to
pass key in the form of String and argument two will accept value in the of
object.
By using get attribute method we can get the values we have to pass key in
the form of String to get attribute method and it will return value in the form
of object.
Cookie:-
Drawbacks of Cookie:-
One Cooke can hold a single value.
Cookie does not accepts space.
The value type of Cookie is String.
The maximum size of Cookie is 4kb.
JSP:-
Tags if JSP:-
By using JSP tags we can write JAVA code inside JSP pages.
There are three JSP tags
1. Declaration tag
2. Scriptlet
3. Expression
Declaration:-
Declaration tag is a class Scope tag we can declare variables , methods and
blocks.
The code written inside declaration tag will be translated to class block of
translated jsp class.
Syntax:- <%! %> .
Scriptlist:-
Expression:-
Expression tag is used for display content on web browser.
Expression tag contain only one argument and it can accept method calls if
method contains return type.
Syntax:- <%= %> .
Jsp Directives:-
Page:-
in JSP file page directives are use-full to import classes , interface and
packages.
Page directives also contains meta data about JSP pages like language ,
content type etc.
Syntax:- <%@page key=value %>
Include:-
In JSP Include directives is used for including one page response into
another page.
Syntax:- <%@include file=filename %>.
Taglib:-
In JSP taglib directive is used for importing custom tags to utilize the custom
tags in current JSP file.
Syntax:- <%@taglib %>.
Jsp file internally converts into servlet class so JSP files are considered as
dynamic resource.
While translation class will extend http servlet and implements http jsp base.
http jsp base interface contains three abstract methods
SERVLET & JSP
1. _jspInit ( ).
2. _jspDestroy( ).
3. _jspService(request req , response)
Container is responsible to provide implementation for _jspInit and
_jspDestroy ( ).
Programmer is responsible to provide implementation for _jspService( ).
Translates jsp class name will be jspfilename_Jsp.
Servlet ( I )
Jsp file
(interface)
httpjspfile
Generic Servlet ( AC )
(Interface)
Home.jsp
3. Initialization. -------->jspInit( )
4. Request processing. -------->jspService( )
5. De-instantiation. --------->jspDestroy( )
In jsp file to build java codes we frequently use some objects like http servlet
request , http servletresponse……. etc.
In jsp files all the frequently used object references will be available by
default these objects are known as implicit Objects.
Ref Type
application Servlet context
config Servlet config
out Jspwritter
page Object
pagecontext Pagecontext
request Httpservletrequest
response Httpservletresponse
session Httpsession
Jsp actions:- by using jsp actions we can avoid java codes from jsp file.