Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

print doubts in tags......

 
faiza haris
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to confirm print statements, in jsp , start and after tags, like without start and other cases....lets start with this one!
TestdoAfterBody.java

TestdoAfterBodyjsp.jsp

testdoafterbodytag.tld

web.xml
 
faiza haris
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey where did the smiley's come from!!! ahh i guess the code is laughing at me!!!
can anybody help me with its compilation?
i get the error
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 10 in the jsp file: /TestdoAfterBodyjsp.jsp
Generated servlet error:
C:\Tomcat\work\localhost\Testdoafterbody\_0002fTestdoAfterBodyjsp_jsp.java:63: Class org.apache.jsp.TestdoAfterBody not found.
TestdoAfterBody _jspx_th_faizaTag_doafter_0 = new TestdoAfterBody();
^

An error occurred at line: 10 in the jsp file: /TestdoAfterBodyjsp.jsp
Generated servlet error:
C:\Tomcat\work\localhost\Testdoafterbody\_0002fTestdoAfterBodyjsp_jsp.java:63: Class org.apache.jsp.TestdoAfterBody not found.
TestdoAfterBody _jspx_th_faizaTag_doafter_0 = new TestdoAfterBody();
^
2 errors
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:284)

now i understand the laughter!
thanx
faiza
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've heard of this bug on some servers. Put the tag in a package.

and chage the tld to
< tag-class>mypackage.TestdoAfterBody< /tag-class>
and try it again.
Seems if a Tag Class doesn't specify a package, instead of defaulting to no package or the root package, it defaults to the package the JspPage is in.
[ February 13, 2002: Message edited by: Carl Trusiak ]
 
Srini Admala
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, tag class has to be in a package.
I tested it and it works fine.
I get the following text in the browser :
"in do start tagHellohow are you?"
-srini
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is especially true for JavaBeans also.
Hence it is always a good idea (make your
appln protable) to put our beans and tags
in a package.....like we do in any grocery store...
- satya
 
faiza haris
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah, it was working in the package....and satya i hate doing the grocery, which led me to forget the package, and try this example
Anyway, i wanted to test the tag flow, which is as below?:
load tld file
read custom tag from the jsp file
locate the class from the tag via tld
Create new instance of class if no old available for re use
invoke doStartTag, print statment, since body included so print jsp body,return to doAfterBody
invoke doAfterBody, print statement and since not repeated, ccall doEndTag inherited frm the Tag which does nothing by default.
What if the doStartTag returns EVAL_BODY_BUFFERED , THE .java implements BodyTagSupport.
will come back later with diff scenarios.....
thanx
faiza
 
faiza haris
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The doAfterBody prints how are you, with the skip body, and not as the answer says???Plz confirm? i think thats the right behaviour.....so the ans must be wrong???
thanx....and heres the q&a below:
public class body extends TagSupport {
public int doStartTag() throws JspException{
return EVAL_BODY_INCLUDE;
}
public int doAfterBody() throws JspException {
try { pageContext.getOut().print("how are you?"); }catch(IOException e) {}
return SKIP_BODY;
}
}
what will be printed out by the following part of a jsp page?
<prefix:sufix>
<i>Hello</i>
</prefix:sufix>
1) The tag handler won't compile.
2) The jsp page will print Hello how are you?
3) The jsp page will print how are you? Hello
4) The jsp page will print Hello
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
faiza:
I din't follow your explanation....
I think the answer is 2.
"Hellohow are you"
The SKIP_BODY means skip anything after this
end tag in the JSP. Not the entire body of the
JSP.
- satya
 
faiza haris
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
u'r right, actually the ans given was 4 which is wrong.
Anyway thanx for the help
faiza
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic