SlideShare a Scribd company logo
1 of 12
Servlet and JSP
Interview questions
By Sujata Regoti
1.What is difference between include action and include directive in
JSP?
Include directive Include action
Resource included during jsp translation time request time
change on included resource
reflect after
Compilation of JSP (static) Next request (dynamic)
attribute to specify resource file page
Can pass parameter No yes
Example <%@ include file="loan.jsp" %> <jsp:include page="header.jsp">
<jsp:param name="some"
value="thing"/>
</jsp:include>
2.How do you define application wide error page in JSP
//error.jsp
<%@ page isErrorPage="true"%>
//login.jsp
<%@ page errorPage="error.jsp"%>
If any unhandled Exception thrown from login.jsp , error.jsp error page will be
invoked
3.Difference between sendredirect and forward in Servlet
sendredirect forward
Declared in interface HttpServletResponse RequestDispatcher
syntax void sendRedirect(String url) forward(ServletRequest request,
ServletResponse response)
Visible to client yes no
Further processing within Different server or module Same server
Comparison Slower than forward as
completer new request created
Faster than sendredirect
4.What is difference between Web Server and Application Server
Read more: http://java67.blogspot.com/2012/10/servlet-jsp-interview-
questions-answer-faq-experience.html#ixzz49IBh21A6
4
Web Server Application Server
support Only Servlets and JSP distributed transaction and EJB
super Can be subpart of Application
server
Include Web Server
Logical difference Provide http protocol level service Provide web service and expose
business level service
Resource utilization Less so less heavy than
application server
High so more heavy than web
server
Example Apache tomcat Glassfish,JBoss,WAS
5.What is difference between ServletContext and ServletConfig
ServerConfig ServerContext
Available for one per servlet Web application
scope Like local parameter for particular
servlet
global parameter associated with
whole application
Where name value pair defined
in web.xml
inside the servlet section outside of servlet tag
Method to get object getServletConfig() getServletContext()
Example To get Shopping cart details To get the MIME type of a file or
application session related
information
6.What is difference between GET and POST method in HTTP protocol
Read more: http://java67.blogspot.com/2012/10/servlet-jsp-interview-
questions-answer-faq-experience.html#ixzz49IJORF59
Read more: http://java67.blogspot.com/2012/10/servlet-jsp-interview-
questions-answer-faq-experience.html#ixzz49IGWgAiy
GET POST
Passes request parameter In URL string In request body
Limit to send data only pass limited amount of data
depending on browser
large amount of data to server i.e.
no limit
Can bookmarked or catched yes no
Mostly used for view purpose update purpose
Suitable for sensitive and
confidential information
No yes
7.What is difference between URL Encoding and URL rewriting
URL Encoding URL rewriting
purpose Way to pass string to server
containing special characters by
converting special characters
Technique used maintain user
session if cookies are not
enabled or not support
Methods used java.net.URLEncoder.encode()
and
java.net.URLDecoder.decode()
java.servlet.http.HttpServletResp
onse.encodeURL(String url) and
encodeRedirectURL(String URL)
URL changes special character replaced by
another character like space with
ā€˜%20ā€™
session id is appended to URL
8.What is difference between Servlet and JSP
Servlet JSP
What it is Java program can be used to create
dynamic web pages
webpage scripting language that can
generate dynamic content.
Speed faster compared to JSP slower compared to Servlet as it takes
compilation time to convert into Java
Servlets.
MVC part act as a controller act as a view
Custom tag facility Not available Available e.g.tags used to call Java
beans directly
When to preferr more processing and manipulation
involved
not much processing of data required
9.What is war file and how to create?
A war (web archive) file specifies the web elements. A servlet or jsp project can be
converted into a war file. Moving one servlet project from one place to another will
be fast as it is combined into a single file.
The war file can be created using jar tool found in jdk/bin directory. If you are
using Eclipse or Netbeans IDE, you can export your project as a war file.
To create war file from console, you can write following code.
jar -cvf abc.war *
10.What is difference between GenericServlet and HttpServlet?
The GenericServlet is protocol independent whereas HttpServlet is HTTP protocol
specific. HttpServlet provides additional functionalities such as state management
etc.
Thank You
http://www.regotiss.github.io

More Related Content

What's hot

Android Services
Android ServicesAndroid Services
Android Services
Ahsanul Karim
Ā 
Streams In C# Tutorial
Streams In C# TutorialStreams In C# Tutorial
Streams In C# Tutorial
Simplilearn
Ā 
Java for Recruiters
Java for RecruitersJava for Recruiters
Java for Recruiters
ph7 -
Ā 

What's hot (20)

Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java Programming
Ā 
JSP Error handling
JSP Error handlingJSP Error handling
JSP Error handling
Ā 
Understanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple StepsUnderstanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple Steps
Ā 
Remote Method Invocation (Java RMI)
Remote Method Invocation (Java RMI)Remote Method Invocation (Java RMI)
Remote Method Invocation (Java RMI)
Ā 
Web container and Apache Tomcat
Web container and Apache TomcatWeb container and Apache Tomcat
Web container and Apache Tomcat
Ā 
Hibernate
HibernateHibernate
Hibernate
Ā 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
Ā 
Tomcat Server
Tomcat ServerTomcat Server
Tomcat Server
Ā 
Introduction Node.js
Introduction Node.jsIntroduction Node.js
Introduction Node.js
Ā 
Android JNI
Android JNIAndroid JNI
Android JNI
Ā 
JAVA ENVIRONMENT
JAVA  ENVIRONMENTJAVA  ENVIRONMENT
JAVA ENVIRONMENT
Ā 
Android Services
Android ServicesAndroid Services
Android Services
Ā 
Java Concurrency by Example
Java Concurrency by ExampleJava Concurrency by Example
Java Concurrency by Example
Ā 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
Ā 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
Ā 
Streams In C# Tutorial
Streams In C# TutorialStreams In C# Tutorial
Streams In C# Tutorial
Ā 
JDBC
JDBCJDBC
JDBC
Ā 
Java for Recruiters
Java for RecruitersJava for Recruiters
Java for Recruiters
Ā 
Spring mvc
Spring mvcSpring mvc
Spring mvc
Ā 
Javascript Roadmap - The Basics
Javascript Roadmap - The BasicsJavascript Roadmap - The Basics
Javascript Roadmap - The Basics
Ā 

Similar to Servlet and jsp interview questions

JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGES
Kalpana T
Ā 
Jsp and Servlets
Jsp and ServletsJsp and Servlets
Jsp and Servlets
Raghu nath
Ā 
Web Application Deployment
Web Application DeploymentWeb Application Deployment
Web Application Deployment
elliando dias
Ā 

Similar to Servlet and jsp interview questions (20)

Jsp
JspJsp
Jsp
Ā 
Introduction to the Servlet / JSP course
Introduction to the Servlet / JSP course Introduction to the Servlet / JSP course
Introduction to the Servlet / JSP course
Ā 
JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGES
Ā 
JavaEE6 my way
JavaEE6 my wayJavaEE6 my way
JavaEE6 my way
Ā 
JEE Course - The Web Tier
JEE Course - The Web TierJEE Course - The Web Tier
JEE Course - The Web Tier
Ā 
Server side programming bt0083
Server side programming bt0083Server side programming bt0083
Server side programming bt0083
Ā 
J2EE jsp_01
J2EE jsp_01J2EE jsp_01
J2EE jsp_01
Ā 
Jsp and Servlets
Jsp and ServletsJsp and Servlets
Jsp and Servlets
Ā 
Servlets
ServletsServlets
Servlets
Ā 
Spatial approximate string search Doc
Spatial approximate string search DocSpatial approximate string search Doc
Spatial approximate string search Doc
Ā 
Web Application Deployment
Web Application DeploymentWeb Application Deployment
Web Application Deployment
Ā 
C:\fakepath\jsp01
C:\fakepath\jsp01C:\fakepath\jsp01
C:\fakepath\jsp01
Ā 
JSP overview
JSP overviewJSP overview
JSP overview
Ā 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
Ā 
Java servlet technology
Java servlet technologyJava servlet technology
Java servlet technology
Ā 
Servlet by Rj
Servlet by RjServlet by Rj
Servlet by Rj
Ā 
Jsp and jstl
Jsp and jstlJsp and jstl
Jsp and jstl
Ā 
Online grocery store
Online grocery storeOnline grocery store
Online grocery store
Ā 
J2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsJ2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - Components
Ā 
Ajp notes-chapter-06
Ajp notes-chapter-06Ajp notes-chapter-06
Ajp notes-chapter-06
Ā 

More from Sujata Regoti

More from Sujata Regoti (9)

Social media connecting or disconnecting
Social media connecting or disconnectingSocial media connecting or disconnecting
Social media connecting or disconnecting
Ā 
Image retrieval
Image retrievalImage retrieval
Image retrieval
Ā 
Key management
Key managementKey management
Key management
Ā 
Web mining tools
Web mining toolsWeb mining tools
Web mining tools
Ā 
Git,Github,How to host using Github
Git,Github,How to host using GithubGit,Github,How to host using Github
Git,Github,How to host using Github
Ā 
Technical aptitude test 2 CSE
Technical aptitude test 2 CSETechnical aptitude test 2 CSE
Technical aptitude test 2 CSE
Ā 
Technical aptitude Test 1 CSE
Technical aptitude Test 1 CSETechnical aptitude Test 1 CSE
Technical aptitude Test 1 CSE
Ā 
Big Data
Big DataBig Data
Big Data
Ā 
Inflation measuring
Inflation measuringInflation measuring
Inflation measuring
Ā 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
Ā 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
Christopher Logan Kennedy
Ā 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
Ā 

Recently uploaded (20)

DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
Ā 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
Ā 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
Ā 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
Ā 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Ā 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Ā 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
Ā 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governance
Ā 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Ā 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
Ā 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
Ā 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
Ā 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
Ā 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
Ā 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
Ā 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
Ā 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
Ā 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
Ā 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
Ā 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
Ā 

Servlet and jsp interview questions

  • 1. Servlet and JSP Interview questions By Sujata Regoti
  • 2. 1.What is difference between include action and include directive in JSP? Include directive Include action Resource included during jsp translation time request time change on included resource reflect after Compilation of JSP (static) Next request (dynamic) attribute to specify resource file page Can pass parameter No yes Example <%@ include file="loan.jsp" %> <jsp:include page="header.jsp"> <jsp:param name="some" value="thing"/> </jsp:include>
  • 3. 2.How do you define application wide error page in JSP //error.jsp <%@ page isErrorPage="true"%> //login.jsp <%@ page errorPage="error.jsp"%> If any unhandled Exception thrown from login.jsp , error.jsp error page will be invoked
  • 4. 3.Difference between sendredirect and forward in Servlet sendredirect forward Declared in interface HttpServletResponse RequestDispatcher syntax void sendRedirect(String url) forward(ServletRequest request, ServletResponse response) Visible to client yes no Further processing within Different server or module Same server Comparison Slower than forward as completer new request created Faster than sendredirect
  • 5. 4.What is difference between Web Server and Application Server Read more: http://java67.blogspot.com/2012/10/servlet-jsp-interview- questions-answer-faq-experience.html#ixzz49IBh21A6 4 Web Server Application Server support Only Servlets and JSP distributed transaction and EJB super Can be subpart of Application server Include Web Server Logical difference Provide http protocol level service Provide web service and expose business level service Resource utilization Less so less heavy than application server High so more heavy than web server Example Apache tomcat Glassfish,JBoss,WAS
  • 6. 5.What is difference between ServletContext and ServletConfig ServerConfig ServerContext Available for one per servlet Web application scope Like local parameter for particular servlet global parameter associated with whole application Where name value pair defined in web.xml inside the servlet section outside of servlet tag Method to get object getServletConfig() getServletContext() Example To get Shopping cart details To get the MIME type of a file or application session related information
  • 7. 6.What is difference between GET and POST method in HTTP protocol Read more: http://java67.blogspot.com/2012/10/servlet-jsp-interview- questions-answer-faq-experience.html#ixzz49IJORF59 Read more: http://java67.blogspot.com/2012/10/servlet-jsp-interview- questions-answer-faq-experience.html#ixzz49IGWgAiy GET POST Passes request parameter In URL string In request body Limit to send data only pass limited amount of data depending on browser large amount of data to server i.e. no limit Can bookmarked or catched yes no Mostly used for view purpose update purpose Suitable for sensitive and confidential information No yes
  • 8. 7.What is difference between URL Encoding and URL rewriting URL Encoding URL rewriting purpose Way to pass string to server containing special characters by converting special characters Technique used maintain user session if cookies are not enabled or not support Methods used java.net.URLEncoder.encode() and java.net.URLDecoder.decode() java.servlet.http.HttpServletResp onse.encodeURL(String url) and encodeRedirectURL(String URL) URL changes special character replaced by another character like space with ā€˜%20ā€™ session id is appended to URL
  • 9. 8.What is difference between Servlet and JSP Servlet JSP What it is Java program can be used to create dynamic web pages webpage scripting language that can generate dynamic content. Speed faster compared to JSP slower compared to Servlet as it takes compilation time to convert into Java Servlets. MVC part act as a controller act as a view Custom tag facility Not available Available e.g.tags used to call Java beans directly When to preferr more processing and manipulation involved not much processing of data required
  • 10. 9.What is war file and how to create? A war (web archive) file specifies the web elements. A servlet or jsp project can be converted into a war file. Moving one servlet project from one place to another will be fast as it is combined into a single file. The war file can be created using jar tool found in jdk/bin directory. If you are using Eclipse or Netbeans IDE, you can export your project as a war file. To create war file from console, you can write following code. jar -cvf abc.war *
  • 11. 10.What is difference between GenericServlet and HttpServlet? The GenericServlet is protocol independent whereas HttpServlet is HTTP protocol specific. HttpServlet provides additional functionalities such as state management etc.