Hi Garann,
If you take a look at the generated Java Servlet code for your JSP it
should become clear why this doesn't work. The declaration is outside of
the service method of your JSP. Basically this means you can't use any
of the implicit objects directly as if you were writing a scriptlet.
To solve the problem you've got some choices. The easy but messy way
would be to make your methods take a HttpServletRequest object as a
parameter. So each time you call them, you'd pass in the request and use
it like you currently are trying.
EG:
<%! public String mkDate(HttpServletRequest) {
...
<%= mkDate(request) %>
A better solution would be to use a object such as a JavaBean or Custom
tag to abstract these methods. It would remove the spaghetti code
completely.
There are some good JSP links, articles, and tutorials on JSP Insider
(http://www.jspinsider.com). They will help you with this if you are
interested.
Cheers,
Jayson Falkner
[EMAIL PROTECTED]
Means, Garann R. 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
>
> .
>
>
===========================================================================
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