aspose file tools*
The moose likes JSP and the fly likes Why are the implicit objects not available in declarative part of JSP? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Why are the implicit objects not available in declarative part of JSP?" Watch "Why are the implicit objects not available in declarative part of JSP?" New topic
Author

Why are the implicit objects not available in declarative part of JSP?

Saeed Amer
Ranch Hand

Joined: Jan 20, 2004
Posts: 140
Why are the implicit objects not available in declarative part of JSP? For example, following JSP code will fail to compile successfully:

<html>
<%! String name=request.getParameter(``name``); %>
Name of person is <%=name %>
</html>

Anthony Watson
Ranch Hand

Joined: Sep 25, 2003
Posts: 327
JSP pages are translated into servlets and then they are compiled before they can be viewed. Declaring a variable in a JSP page means that the variable will become a (non static) class attribute in the corresponding servlet. At the time when the servlet is compiled, there is no such thing as a request because a request can't come in until after the servlet is compiled and made available by the container.


Anthony W.<br />MCP, SCJP 1.4, SCJD, SCWCD 1.3, SCWCD 1.4, SCBCD
Rovas Kram
Ranch Hand

Joined: Aug 08, 2003
Posts: 135
In other words, request is a input parameter for the method _jspService therefore can only be accessed within _jspService.
Saeed Amer
Ranch Hand

Joined: Jan 20, 2004
Posts: 140
Great!

Thank you so much both!
Saeed Amer
Ranch Hand

Joined: Jan 20, 2004
Posts: 140
and it worked OK when I changed the code to:

<html>
<% String name=request.getParameter("name"); %>
Name of person is <%=name %>
</html>

bcoz now the variable declaration for "name" would become part of the _jspService() method which has access to the implicit object "request" (and that is exactly what you two said above)!

Thanks again!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Why are the implicit objects not available in declarative part of JSP?