• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

valid implicit variables in a JSP

 
Sherif Shehab
Ranch Hand
Posts: 487
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all
Is "this" valid implicit variables in a JSP page?
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Download the JSP spec

Search for "Implicit" to find that it is section 1.8.3.

Check the list of implicit objects.

Let's see - there's request, response, pageContext, session, application, out, config, page, and exception. Nope, no this. Hey, a footnote!

a. When the scripting language is java then page is a synonym for this in the body of the page.


Cool. My "scripting" language (meaning the language inside the scripting tags) is always Java when I program. So even though there's no this implicit object, I can still use page, which is just as good, if not a little better.
 
Sherif Shehab
Ranch Hand
Posts: 487
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply, but when i was answering an exam in ethurware i found this question :

Which of the following are valid implicit variables in a JSP page?

Select 2 correct options
a error
Variable name is 'exception' and it is only available in error pages.

b page


c this
This is same as page.

d root
there is no such variable.

e context
It is 'pageContext'

General Comments

Following are the implicit variables that are available in a JSP.
request, response, pageContext, session (available only when <%@ page session="true" %> or there is no page directive with session attribute in that page), application, out, config, page and exception(only available where <%@ page isErrorPage="true" %> ).

Right answer as they say : B,C. My answer was B,E . i know that E is wrong because it must be PageContext rather context.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it might be right that this could be used as valid code in a scriptlet. In fact, I tried it out on Tomcat. I made a JSP with the name myJSP.jsp with the following contents:
<%= this.getClass() %>

and my output was:
class org.apache.jsp.myJSP_jsp

I tried the same for <%= page.getClass() %> and received the same result.

However, this is NOT considered an implicit object according to the spec. So in that respect the mock exam is still wrong and the real exam will not do this.

I don't think I've ever used page or this in a JSP in the real world before anyway, by the way.
 
Sherif Shehab
Ranch Hand
Posts: 487
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Marc ..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic