1. Servlet Spec says : After sendError() or sendRedirect() anything written to ( out.println() ) is ignored . There is no exception thrown . So why all the mock exams say it will give IllegalStateException . Also what happens if write something after forward() ?
I tried all these and tomcat doesn't give any error ( not in logs also ). Can you give me the solution for above 3 scenarios ?
2. In JSP 2.0 tld file has to have <body-content> tag . It has become mandatory . This is what HF Servlets and JSP also say . Is it true ?
Hi , Please check the earlier messages and you will get the answer.
The answer is when the response is committed that means you have already sent something to the browser . In this case even if the exception is thrown it will be just logged in some tomcat specific log.
The answer is the IllegalStateException will be thrown but the browser will not know that.
body-content is still required as minOccurs="0" only for the optional elements
--------------
- <xsd:complexType name="tagType"> + <xsd:annotation> <xsd ocumentation>The tag defines a unique tag in this tag library. It has one attribute, id. The tag element may have several subelements defining: description Optional tag-specific information display-name A short name that is intended to be displayed by tools icon Optional icon element that can be used by tools name The unique action name tag-class The tag handler class implementing javax.servlet.jsp.tagext.JspTag tei-class An optional subclass of javax.servlet.jsp.tagext.TagExtraInfo body-content The body content type variable Optional scripting variable information attribute All attributes of this action that are evaluated prior to invocation. dynamic-attributes Whether this tag supports additional attributes with dynamic names. If true, the tag-class must implement the javax.servlet.jsp.tagext.DynamicAttributes interface. Defaults to false. example Optional informal description of an example of a use of this tag tag-extension Zero or more extensions that provide extra information about this tag, for tool consumption</xsd ocumentation> </xsd:annotation> - <xsd:sequence> <xsd:group ref="j2ee escriptionGroup" /> <xsd:element name="name" type="j2ee:tld-canonical-nameType" /> + <xsd:element name="tag-class" type="j2ee:fully-qualified-classType"> - <xsd:annotation> <xsd ocumentation>Defines the subclass of javax.serlvet.jsp.tagext.JspTag that implements the request time semantics for this tag. (required)</xsd ocumentation> </xsd:annotation> </xsd:element> + <xsd:element name="tei-class" type="j2ee:fully-qualified-classType" minOccurs="0"> - <xsd:annotation> <xsd ocumentation>Defines the subclass of javax.servlet.jsp.tagext.TagExtraInfo for this tag. (optional) If this is not given, the class is not consulted at translation time.</xsd ocumentation> </xsd:annotation> </xsd:element> - <xsd:element name="body-content" type="j2ee:body-contentType"> - <xsd:annotation> <xsd ocumentation>Specifies the format for the body of this tag. The default in JSP 1.2 was "JSP" but because this is an invalid setting for simple tag handlers, there is no longer a default in JSP 2.0. A reasonable default for simple tag handlers is "scriptless" if the tag can have a body.</xsd ocumentation> </xsd:annotation> </xsd:element> <xsd:element name="variable" type="j2ee:variableType" minOccurs="0" maxOccurs="unbounded" /> <xsd:element name="attribute" type="j2ee:tld-attributeType" minOccurs="0" maxOccurs="unbounded" /> <xsd:element name="dynamic-attributes" type="j2ee:generic-booleanType" minOccurs="0" /> + <xsd:element name="example" type="j2ee:xsdStringType" minOccurs="0"> - <xsd:annotation> <xsd ocumentation>The example element contains an informal description of an example of the use of a tag.</xsd ocumentation> </xsd:annotation> </xsd:element> + <xsd:element name="tag-extension" type="j2ee:tld-extensionType" minOccurs="0" maxOccurs="unbounded"> - <xsd:annotation> <xsd ocumentation>Tag extensions are for tool use only and must not affect the behavior of a container.</xsd ocumentation> </xsd:annotation> </xsd:element> </xsd:sequence> <xsd:attribute name="id" type="xsd:ID" /> </xsd:complexType>
Specifies the format for the body of this tag. The default in JSP 1.2 was "JSP" but because this is an invalid setting for simple tag handlers, there is no longer a default in JSP 2.0. A reasonable default for simple tag handlers is "scriptless" if the tag can have a body.
that means for Custom tags <body-content> is compulsory and for Simple tage its by default "scriptless" .
About your first question, here is an excerpt from the HttpServletResponse javadoc:
It says that an IllegalStateException is thrown if the response has been commited before calling the sendError method (the same applies for sendRedirect). So, you are right when you say that no exception would be raised if you write something after one of these two method has been called.
Post by:autobot
The moustache of a titan! The ad of a flea:
a bit of art, as a gift, the permaculture playing cards