• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jspInit

 
sangeeta kapoor
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why can't application implicit variable be used inside jspInit().

The following code fails

<html>
<body>
<%!
public void jspInit() {
application.setAttribute("s", "abc");
}
%>
<%= application.getAttribute("s")%>
</body>
</html>
 
Durgaprasad Guduguntla
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The implicit objects are the local variables in the _jspService method and obtained from pageContext within _jspService method and hence the implicit objects are not available in jspInit() method. Therefore it is invalid to set the attributes in the JSP declaration tags. Please take a look at the following container generated servlet code snippet for a JSP page:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic