"Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration."- Stan Kelly-Bootle
"Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration."- Stan Kelly-Bootle
You put an "!" in there, as you'll see, and that means you're declaring an instance variable for the class that the JSP represents. And when you declare an instance variable, you don't have access to the parameters of the method where your JSP code lives, and "request" is one of those parameters.Originally posted by David McCombs:
Why does this line in the jsp generates a compiler error(request cannot be resolved): <%! String s = request.getContextPath(); %>
Originally posted by Bear Bibeault:
Do you understand the implications of using <%! over the <% notation?
Therein lies the answer to your question.
And neither of the discussed paths are really appropriate for classpath issues. What exactly are you trying to do?
"Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration."- Stan Kelly-Bootle
Originally posted by Paul Clapham:
You put an "!" in there, as you'll see, and that means you're declaring an instance variable for the class that the JSP represents. And when you declare an instance variable, you don't have access to the parameters of the method where your JSP code lives, and "request" is one of those parameters.
Of course all this requires you to understand how JSP code is converted into a Java class, which is really more than JSP coders should be made to understand. So I'd advise putting such code into a servlet, where it's clear what goes where.
And I'd also advise you not to try accessing files in your web context. In some servlet containers you don't even have files to access, the whole application is run out of a jar file. If you want to read from something in your web context, then get an InputStream something like this:
"Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration."- Stan Kelly-Bootle
Originally posted by David McCombs:
<%! is used for declaring variables,
"Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration."- Stan Kelly-Bootle
girl power ... turns out to be about a hundred watts. But they seriuosly don't like being connected to the grid. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|