Home  |   STIU  |   WOW  |   SCJP  |   SCDJWS   |   JEE FAQ  |   About US  |  

FAQ
  Java FAQ
  JSP FAQ
  Servlet FAQ
 

Advertisement

Printer-friendly version Printer-friendly version | Send this 
article to a friend Mail this to a friend

Previous Next vertical dots separating previous/next from contents/index/pdf Contents

Advertisement
XyzWs JSP FAQ: Why are the implicit objects not available in declarative part of JSP?

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


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

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

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.

In other words, request is a input parameter for the _jspService() method, therefore can only be accessed within _jspService() method.


Previous Next vertical dots separating previous/next from contents/index/pdf Contents

Support  | Feedback  | Help