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

JSP code legal?

 
nagalatha mitta
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends
my doubt is:
Is the following JSP code legal? Select the one correct statement.
<%@page info="test page" session="false"%>
<%@page session="false"%>

A. Yes. This is legal JSP syntax.
B. No. This code will generate syntax errors.

According to my knowledge option A. is correct,but javaprepare.com says option B. is correct because Except the import attribute of page directive, all the other attributes of page directive cannot be specified more than once. In this example session attribute is specified twice.

if anybody knows which option is correct .please let me know
Thanks in advance
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only the import and pageEncoding attributes can appear several times, no matter what.
Other attributes can appear several only if the value is the same for each appearance.

In your mock, session is set twice to false, which is legal. Answer is A.
If session was set to a different value, it would not be legal.
 
khushhal yadav
Ranch Hand
Posts: 242
Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Christophe Verre

I am agree with you.
But I think only import can occur many times not pageEncoding with different values.
pageEncoding cannot have different values.

And moreoever pageEncoding and contentType should appear at the beginning of page, while others can appear any where in your JSP page.

Please clear that thing.

Regards,
Khushhal
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pageEncoding cannot have different values.

Sorry, I was not clear. pageEncoding can be used several times in the same translation unit, but not in the same page.
In the same page, only import can be used several times with different values.

Thank you for pointing this out.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I agree with Christoph that only import can appear several times with different values. All the others can appear only once and if appeared twice, their values must be same otherwise you will get a 500 error when you try to access that jsp.
 
nagalatha mitta
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends
Thanks for clearing my dought


Thanks and Regaards
Nagalatha
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic