Responce once commited, any subsequent redirect operations will throw an IllegalStateException?
public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
PrintWriter out = response.getWriter();
String dbValue = getValueFromDB ();
if (dbValue == null) response.sendError (HttpServletResponse.SC_NOT_FOUND, "DB Lookup Failed");
response.sendRedirect ("Form.jsp");
}
Question:
Consider the following code snippet of above servlet code.
If the getValueFromDB () method returns null , which of the following statements are true?
(A) The code will work without any errors or exceptions
(B) An IllegalStateException will be thrown
(C) A NullPointerException will be thrown
(D) An IOException will be thrown
The correct answer(s):
(B) An IllegalStateException will be thrown
Explanation:
When the sendError() API is called, the response is considered committed and should not be written to
subsequently. Once the response is considered committed, any subsequent redirect operations will throw an
IllegalStateException.
In this above servlet code, the sendError() is invoked when the dbValue is null, which will cause the response to be
committed. Hence, the subsequent response.sendRedirect () method will then cause an IllegalStateException to
be thrown.
Reference: http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/http/HttpServletResponse.html
My Favorite Site's List
-
Build Your Own Test Framework
-
[image: Build Your Own Test Framework]
Learn to write better automated tests that will dramatically increase your
productivity and have fun while doing so...
31 minutes ago
-
Top 5 Big Data and Apache Spark Courses for Java Developers to Learn Online
- Best of Lot [2025]
-
A slowing economy and the recent trend of job cuts in India and elsewhere
have made many programmers anxious about their job security. I receive a
lot of e...
4 hours ago
-
EndOfLife Software packages
-
The "End of Life" (EOL) page for Software provides information on the
release dates, support periods, and security status of different Software
versions. I...
5 months ago
-
How to Install Java on Ubuntu 24.04
-
Connect to us ( @twitter | @facebook )
Java is a versatile programming language that can be installed on Ubuntu
24.04 using different methods, such as “a...
7 months ago
-
Book Review: The Girl in White Gloves by Kerri Maher
-
[image: The Girl in White Gloves]*The Girl in White Gloves by Kerri Maher*
*Goodreads*
I was curious to learn about old Hollywood, but beyond that I wasn't ...
4 years ago
-
convert .pem file to .ppk using puttygen - AWS
-
PEM-Privacy Enhanced Mail is a Base64 encoded DER certificate file
format. PEM certificates are frequently used for web servers as they can
easily be tra...
4 years ago
-
Spring Boot Webflux DynamoDB Tutorial
-
Creating REST API in Spring Boot Webflux and AWS DynamoDB. Step by step
guide for storing retriving data in DynamoDB using Spring Boot Webflux and
exposing...
5 years ago
-
Top Developer Collaboration Tools
-
How to drive your project into a corner? Just in case you wondered, there
are multiple options. The surest one is miscommunication. Considering that
you ca...
5 years ago
-
Highlighting Google Cloud’s talks at Puppetize Live
-
Highlighting Google Cloud’s talks at Puppetize Live
Kristina Psaris-Weis 16 October 2018
Off
[image: Andrew Nhem]
Andrew Nhem
Events — Partn...
6 years ago
-
What are the topics to focus on AWS Certified SysOps Administrator
Associate certification exam preparation?
-
AWS Certified SysOps Administrator Associate exam is comparatively
toughest exam in the associate level exams. Other two exams Solutions
Architect and Dev...
7 years ago
-
Meet The Wattpad Stars: Brittany Geragotelis
-
After 10 years of pounding the pavement with publishers and agents,
Brittany Geragotelis decided to break free from gatekeepers by posting an
original stor...
7 years ago
-
Breaking Down Barriers in Sexual and Reproductive Health Reporting in Africa
-
*This is a guest post by Humphrey Nabimanya, founder of Reach a Hand
Uganda. *
[image: 2016-04-15-1460736651-1435623-huffpo1.jpg]*Journalists and bloggers...
8 years ago
-
Wildfly 8.x : Control maximum number of connections (threads) assigned to
an application
-
In Wildfly, multiple applications can be deployed together. With the
default configuration, there is no control on the maximum number of
connections/threa...
9 years ago
-
POI Hide UnHide Rows Columns Java Example
-
In this tutorial, we will discuss how to hide / unhide rows / columns in an
Excel worksheet using Apache POI, with suitable Java Examples.We will cover
the...
10 years ago
-
OSGi - Road Ahead
-
OSGi has been introduced many times in the past few years and will still
require some in the future1. With so many introductions, one might be
inclined to ...
11 years ago
-
The Two Ways of Doing a Job
-
Whether it's deployment, development, performance tuning, troubleshooting
or something else, there are two fundamentally different ways of doing your
job: ...
12 years ago
-
List of demonstrations on this page And How To Find Them And How To Get
Them.
-
Here Is A List of demonstrations on this page with the link back to the
tutorial :
How To Add A Scrolling Recent Posts Gadget To Your Blog
You Can See T...
15 years ago
-
Newest Blogger Templates
-
Click for more templates below:
Favorite templates | Previous templates 161 - 170 >>
15 years ago
-
Blog Members
-
Here is how to show off your blog members. These are members of your blog
community who have joined your blog through Google Friend Connect. Put all
your m...
15 years ago
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
#update below script more than 500 posts
No comments:
Post a Comment
I'm certainly not an expert, but I'll try my hardest to explain what I do know and research what I don't know.