I apologize, I am dancing around my main questions here. What would be best - to try and work this all from the jsp page (sounds like no, because I do need multiple people to use this application at once), or to put it in a separate servlet? Or a Java Bean?
I understand what people have said about how to use the methods inside the page, but my question has become more philosophical at this point. My understanding is that functionality reused within a page should be a servlet, classes reused throughout the app should be Java Beans, and things called by multiple applications would be EJB's. Is that right? At any rate, thank you all for your careful explanations. Garann PS - Celeste, thank you for pointing out that this is still OOP. I'm not a VB programmer, but I was approaching my changeovers as a find-and-replace kind of thing, not really considering that these are STILL Java programs. Keeping that in mind is going to help me a lot in learning jsp. -----Original Message----- From: Borislav Iordanov [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 23, 2002 11:32 AM To: [EMAIL PROTECTED] Subject: Re: Where to put methods for a jsp page? 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 =========================================================================== 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
