• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

page.getServletInfo()

 
Kan Qiu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, In the book SCWCD Exam Study Kit, Chapter 12, page 214, it says <%= page.getServletInfo() %> will cause Error. But I tried a jsp like bellow, and it worked and print the info.
<%@ page info="my test page again" %>
<html>
<body>
<%= page.getServletInfo() %>
</body></html>
So, can some one explain why? I run this in RexIP server.
 
Mark Bensing
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just tried this on Tomcat 4.1.8 and I get an error. In the servlet generated from the JSP page I see the following code generated in _jspInit() as described in the book:

My only guess is that the servlet container that you are using declares the page variable to be of a type that is a subclass of Servlet instead of Object. Check the generated servlet to see if this is the case and let us know the results.
Mark
 
Kan Qiu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The RexIP server just generate class file, not java file, so I can not see the code, but I think you are right. and I also tried this in Tomcat, then I got error. So in general, we should not call page.getServletInfo().
Thanks.
 
Amer Khan
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Object page = this;
The page object represents an instance of the servlet class into which the page has been translated [thus the jsp itself] and can be accessed using 'this' reference.The servlet class (In case of web based jsp applications built on Http)must implement the
java.servlet.jsp.HttpJspPage interface.In order to access methods defined by the above interface,the page object must first be casted to that interface.
<%= ((javax.servlet.jsp.HttpJspPage)page).getServletInfo() %>
Note: HttpJspPage extends JspPage,and JspPage extends Servlet interface.
getServletInfo() method belongs to the Servlet interface and is inherited by HttpJspPage interface,so this is also ok.
<%= ((Servlet)page).getServletInfo() %>
[ April 14, 2003: Message edited by: Amer Khan ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic