Peter Bishop wrote:
> Hi,
> Please excuse the naiveté of my question as I am knew to JSP/servlets.
>
> Is it possible to refer to the session & response objects from inside <%!
> declaration %> statements? As such:
>
> <%!
> public void CheckPassword(String strPass) {
> if (strPass.length() < 1 ) {
> session.setAttribute("ErrorMessage",
> "The password field is empty");
> response.sendRedirect("error_message.jsp");
> }
> %>
>
No, this will not work. The reason is that things inside <%! %> are declared at
the class level (i.e. they create methods and instance variables). The JSP
implicit objects are only defined inside the service method of the servlet that is
generated for your JSP page. You would need to pass them as arguments to use them
in a method like CheckPassword().
Of course, I would also encourage you not to put Java code in your JSP pages in the
first place (beans and servlets are a better approach, IMHO) ... but that's a
different issue.
> Pete
>
Craig McClanahan
PS: For a web application framework that implements the separation I suggest, take
a look at the Struts Framework <http://jakarta.apache.org/struts>.
===========================================================================
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://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets