Aharon Naiman wrote:
>
> Dear All,
>
> Hi. I am having two problems with JSP/JavaBeans. Although I am new
> to this arena, I am not at all new to programming and such.
>
> 1) It is not at clear to me (although I have looked some) when a JSP
> is recompiled. My bean development sequence is usually: 1) change
> the bean, 2) recompile it, 3) (as root) stop Tomcat
> (jakarta-tomcat running on Linux), 4) start Tomcat, 5) sometimes I
> even restart apache, 6) reload the JSP page.
>
> For some reason, __sometimes__ this works, and sometimes I need to
> "touch" the JSP in order to tell the system to recompile the JSP.
>
> Would someone please explain to me when a JSP will go and recompile
> itself due to a changed bean, and when not? [...]
Tomcat, and I assume most other containers, only *recompiles* a JSP page
when the page itself is changed, not when a class (such as a bean or
custom action) is changed. However, some containers detect when classes
in the WEB-INF/classes and WEB-INF/lib directories are changed and then
reloads *all* classes for the web application (to avoid ClassCastExceptions).
This mechanism can be enabled for Tomcat but as far as I know, it's buggy
in Tomcat 3.1 and I'm not sure if it's 100% okay in Tomcat 3.2 (beta).
> 2) Okay, this is a doosy. Here is the bean:
>
> package com;
> public class foo {
> private int age;
>
> public void setAge(String ageAsString) { }
> public int getAge() {return age;}
> }
>
> and here is the JSP:
>
> <jsp:useBean id="foo" class="com.foo" scope="session"/>
>
> <html><body>
> <jsp:getProperty name="foo" property="age"/>
> </body></html>
>
> Your first question is: why does the "set" receive a String, and
> the "get" return an int? Good question. The reason is that in
> case there is erred user input, say an age of "mmm", I want to be
> able to catch that. (Of course, in the actual JSPs I use
> property="*".) Now, this simply does not compile. [...]
The JavaBeans spec is a bit vague, but the way it's implemented by
the bean support classes it's clear that a property must be represented by
getter and setter methods of the same type. In your case you use mixed
types so the bean support classes do not accept "age" as a property at
all.
Hans
--
Hans Bergsten [EMAIL PROTECTED]
Gefion Software http://www.gefionsoftware.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
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