Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

can't recognize JSP global variables inside method definitions

843838Jan 27 2006 — edited Jan 29 2006
Hi everyone,

I am relatively new to JSP technology and going through some tutorials now.
For some reason when I try to access global JSP variables like out, session, request or response inside a method declaration as in the following code I get errors that they cannot be resolved. The code does not make a lot of sense but is supposed to run fine:
<%@ page import="java.util.*" %>
<HTML>
<BODY>
<%!
    Date getDate()
    {
        out.println("inside getDate");
        request.getRemoteHost();
        return new Date();
    }
%>
Hello!  <br>
The time is now <%= getDate() %>
</BODY>
</HTML>
Server complains that it cannot resolve out and request although if I use these variables inside scriplets (and not inside method definitions) everything runs fine:
<%
    out.println( date );
    out.println( "<BR>Your machine's address is " );
    out.println( request.getRemoteHost());
%>
What can be the reason for this? Any help is appreciated.
Thanks,
Anton.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 26 2006
Added on Jan 27 2006
2 comments
388 views