How to get boolean value set as an attribute value in request.
Consider the following snippet
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
boolean isOriginal = (boolean) req.getAttribute(“isOriginalFile");
//Some code
}
Where the request may/may not contain the isOriginalFile
attribute. How to handle this?
Assuming that getting
false
when attribute isnull
is what you expect:Then if you set the attribute to anything else than
Boolean.TRUE
(includingnull
) you will getfalse
.You may set it in either way:
But not as String (because it will be then evaluated to
false
):