Hi Garann,

A JSP page is first translated to a Java class, a
servlet, then compiled and executed on each request.
All code outside of your functions is placed in a
single method of the Java servlet and that method has
the 'request', 'response' etc... "implicit" object
declared as local variables. That is way they are
available in the JSP page.

However, when you declare other methods in the JSP,
they don't have those local variables and that is way
it does not compile. You might consider passing a
PageContext or a HttpServletRequest parameter to your
functions, or declaring a member variable like this:

<%!
   HttpServletRequest currentRequest;
%>

<%
  currentRequest = request;
%>

However, the latter method is not suggested as member
variables prevent the JSP container from reusing the
same Java object when serving several requests at a
time.

Hope this help.

--- "Means, Garann R." <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm converting a bunch of asp pages to jsp. The asp
> pages had methods
> running on the server side, so I've left them there
> in the jsp. When I try
> to compile the jsp, I get errors telling me the
> compiler doesn't know
> "request.getParameter", but only within the methods.
> I'll post the code, and
> maybe someone can give me feedback?
>
> <!-- top of page (there are some declarations up
> here, superfluous for these
> methods) -->
> <%! public String mkDate() {
>                 String sHourHTML = "";
>                 String sMinHTML = "";
>                 String sHTML = "";
>
>                 sHTML  = "<select
> name='selCollHour'>";
>
>                 // ...
>                 // ...
>                 // ... this all compiles fine, and
> doesn't use
> request.getParameter
>
>                 return sHTML;
>         } %>
>
> <%!     public String redChem(String root) {
>                 float usrIn = 0;
>                 float lBnd = 0;
>                 float uBnd = 0;
>                 String sRed = "";
>
>                 // these next three lines are
> throwing the errors
>                 usrIn =
> Float.parseFloat(request.getParameter("txtArea" +
> root));
>                 lBnd =
> Float.parseFloat(request.getParameter("hdnLowBnd" +
> root));
>                 uBnd =
> Float.parseFloat(request.getParameter("hdnUpBnd" +
> root));
>
>                 if (usrIn != 0) {
>                         if ((usrIn > uBnd) || (usrIn
> < lBnd)) {
>                                 sRed =
> "style='color:red'";
>                         }
>                         else {
>                                 sRed = "";
>                         }
>                 }
>                 return sRed;
>         } %>
>
>
> Thanks,
> Garann Rose Means
> ITAS1
> WA State Dept. of Corrections
>
>
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with
> body: "signoff JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body:
> "set JSP-INTEREST DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://archives.java.sun.com/jsp-interest.html
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.jsp
>  http://www.jguru.com/faq/index.jsp
>  http://www.jspinsider.com


__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to