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? Thanx.
Of course, this is less urgent, as the obvious workaround (for now,
anyhow) is to always touch the JSP files.
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. I get:
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
Error: 500
Location: /jsp/my-tests/bar.jsp
Internal Servlet Error:
org.apache.jasper.JasperException: Cannot find a method to read property
'age' in a bean of type 'com.foo'
at
org.apache.jasper.runtime.JspRuntimeLibrary.getReadMethod(JspRuntimeLibrary.java:623)
at
org.apache.jasper.compiler.GetPropertyGenerator.generate(GetPropertyGenerator.java:101)
...
at
org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoint.java:338)
at java.lang.Thread.run(Thread.java:475)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Why?? Why does it not see the "get", due to the String in the
"set"? I have studied Larne Pekowsky's book pretty well, and I do
not see this discussed. (Nor on the web.) Of course, if I change
the String to an int, the problem goes away. But I want to catch
the errant input.
OTOH, if I am supposed to change the age to a String, and have all
of the private fields be Strings, in order to be able to catch the
exceptions (as any respectable code should do), and then constantly
covert back and forth, then this should be said in BIG, BOLD
letters that really the only appropriate type for JSP fields is
Strings (and Larne's book should not be using ints all over the
place, IMHO).
Okay, I have said enough. I would most appreciate an answer, and
please email it to me directly (as well), as I do not (yet) frequent
the newsgroups.
Thanx so much,
Aaron
--
Aaron ("Aharon") Naiman | Jerusalem College of Technology--Machon Lev
[EMAIL PROTECTED] | http://hobbes.jct.ac.il/~naiman
===========================================================================
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