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...
1 hour ago
-
How to enable/disable form elements using jQuery? Examples
-
In last couple of tutorials you have learned how to get all selected
checkbox and radio buttons, and in this tutorial, you will learn how to
enable/disab...
3 days 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...
4 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...
6 months ago
-
Demystifying the Top 10 Spring Annotations for 2024
-
Introduction:
Spring annotations are a powerful tool for autoconfiguring Spring and
streamlining the wiring up of components. They serve as metadata that
...
11 months ago
-
Vedic Maths Classes Online - Sydney
-
If you are keen to learn Vedic Maths, and have full commitment and passion
to do so, please reach out to me at this email address for online classes
- stud...
2 years ago
-
Mini-Review Roundup
-
*Mini-Review Roundup*
[image: Marie Antoinette: The Journey]
*Marie Antoinette: The Journey by Antonia Fraser*
Honestly, this was kind of a letdown...
3 years ago
-
Java URL Encoder/Decoder Example
-
Java URL Encoder/Decoder Example – In this tutorial we will see how to URL
encode/decode attributes in Java. Overview URL encoding, is a mechanism
for enco...
4 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
-
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
-
My Notes On Time Series
-
Time Series
Data set for which time lies in one of the axis is known as time series.
Most of the economical data, meteorological data is an example of time...
8 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
-
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...
14 years ago
-
Newest Blogger Templates
-
Click for more templates below:
Favorite templates | Previous templates 161 - 170 >>
14 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.