Servlet API which is used to create a web application that provides many interface
and classes.
Servlet are the server side programs that run on a web server or application server
and act as a middle layer between client and server
Q. What is Web Server?
It is a software and hardware which uses http and other protocol to respond client
request made over the WWW (World Wide Web)
Q. What is Server?
A server is a computer program or device that provides a services to another
computer program and its users
Q. What is Web Container?
It is a component of web server that interact with java servlet
It manage the life cycle of a servlet and it maps and URL (Uniform Resource
Locator) to a particular servlet class or JSP pages.
Java Servlets do not have main methods, so a container is required to load them.
The servlet classes deploy on the web container for execution
Q. In how many ways we can create servlet class?
Servlet
Generic Servlet
HTTP Servlet
Q. What is pom.xml file?
POM stands for Project Object Model where as xml stands for Extensible Markup
Language. It is a configuration file which is used to generate required jar file
from maven central repository with the help of dependency code it is also configure
JDK version in current project
Jakarta Server Pages
It is a technology for developing webpages that support dynamic content which helps
developer to write java code inside html pages by making use of special jsp tags
It is also known as advance technology of servlet API
JSP Special Tags
JSP Comment tag
JSP Scriptlet Tag
<% Java Code %>
Inside scriptlet tag we can create looping statement, decision statement, object
creation, method call statement, variable declaration statement
We cannot write one scriptlet tag to another scriptlet tag
Any code written inside scriptlet tag store inside JSP service() method
JSP Expression Tag
<%= %>
JSP Declaration Tag
It is used to declare member method and variables of servlet class JSP declaration
starts with <%!java code%>
<%!
public int addTwoNumber(int a, int b){
return a+b;
}%>
<%
int sum=addTwoNumbers(123, 123);
System.out.print(Sum);
%>
JSP Directives Tag
It is used to give special instructions to the web container while JSP pages are
getting translated to servlet source code.
It imports all the servlet classes and java classes inside JSP pages
It starts with <%@ %>
JSP implicit Object
JSP supports 9 automatically defined variables, which are also called implicit
object these variables are (request, response, out, session, application, config,
pagecontext, page, exception)
Servlet Context
An object of servlet context is created by the web container at the time of
deploying the project. This object can be used to get configuration information
from web.xml file. Their is only one servlet context object created for every web
application
Servlet Config
An object of servlet config is created by the web container for each servlet
classes. This object can be used to get configuration operation from web.xml file
Advantages of Servlet Config
The core advantage of servlet config is that you dont need to edit the servlet file
if information is modified from web.xml file
Welcome File List
The welcome file list is element of web app, and it is used to define a list of
welcome files. Its some element is Welcome fie that is used too define which JSP
file is going to execute first
Session in Servlet API
What is Session in Servlet
A session usually corresponds to one user, who may visit a-sight (website) multiple
times. The server can maintain a session in many ways such as cookies, url
rewriting hidden form field, HTTP session
We have interfaces in servlet which is used to view and manipulate information
about a session such as the session identifier, session creation time and session
last access time
NOTE: A session is defined as a series of related browser request that come from
the same client during a certain time period
HTTP Session
HTTP Session is an interface which is used to achieve session inside servlet SPI
with the help of its method.
To create the session or get the created session we use get session method which is
present inside HTTP servlet request interface
To set the max active time for current session we use setMaxInactiveInterval(int
args0); method
We pass the time in second
We use set attribute to store user information to current session
Q. Difference between doget and post