• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

For all SCWCD guys : Doubts

 
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

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 ?
 
Sim Kim
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No one can reply to this ???
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sim Kim
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think u didn't read the question properly . The spec says it is ignored and also there are no exception in the logs of tomcat .
 
Ranjit Jana
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check this link. (advice-check previous messages before posting)

https://coderanch.com/t/169085/java-Web-Component-SCWCD/certification/HttpServletResponse-IllegalStateException
 
Ranjit Jana
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
on the question on body-content please refer the dtd it specifies


<!ELEMENT tag (name, tag-class, tei-class?, body-content?, display-name?,
small-icon?, large-icon?, description?, variable*, attribute*,
example?) >

-----

That means body-content is still optional. well this is in 1.2 specification. Correct me If you are using another specification.

You can add your comment on how it works in different specification .

------------

I am adding the 1.1 specification where the whole elements itself were different

<!ELEMENT tag (name, tagclass, teiclass?, bodycontent?, info?, attribute*) >
You need not know 1.1 for the exams
 
Sim Kim
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am refering for JSP 2.0 for <body-content> .
Please let me know ....
 
Ranjit Jana
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
some of the examples I went through had the following as dtd


http://java.sun.com/dtd/web-jsptaglibrary_2_0.dtd

if anyone of you can get this dtd let me know . I am not aware where can we get this dtd. Till then I assume 1.1 is the latest.
 
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I clicked that link .But Page cannot be found ??

Its XSD and not dtd
 
Ranjit Jana
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok I got what you were looking for its a schema definition.

Look at
http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd
so this is the answer .

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>
 
Sim Kim
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Still I am confused . The xsd says :

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" .

Please correct me if I am wrong .
 
Ranch Hand
Posts: 34
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Beware the other head of science - it bites! Nibble on this message:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic