Re: my first bean (tomcat)



ian ward wrote:

thanks for your reply. I may have come over a bit more
helpless/clueless than I am - I hope! I have looked at the Tomcat page
you indicate and I do have some idea about the architecture of a webapp
and where things should go but I am a bit concerned about some of the
other files which need setting. I am finding the doc a bit wordy to
wade thru and I'd like to see a 'recipe' for getting a Bean (capital
'b' in useBean, I checked) going, the main steps, 'cos I seem to be
missing/hashing one of them.

Recipe:

1) Write Java source code for your bean. It should have a no-arg constructor, and, technically, it should be Serializable. Make sure to assign the bean to a named package.

2) Compile the bean's Java code to get a class file for it.

3) Put the bean's class file in the webapp's WEB-INF/classes directory, or jar it up and put the jar in the webapp's WEB-INF/lib directory. In either case, make sure the path (within WEB-INF/classes or within the jar) maps correctly onto the bean's package name.

4) Use a <jsp:useBean .../> action to declare your JSP's use of a bean instance; depending on the bean's scope and the application flow the instance may or may not be newly created for any particular page view.

                             By the way, are you sure I've got a syntax
kind of error in my jsp? the offending line is simple enough.....

<jsp:useBean id="dialogueSystem" scope="request"
class="controllers.impl.C_SystemImpl" />

No, I'm not *sure* that you have a syntax error, but I think it highly likely based on the stack trace. It is possible, however, that the error is not in your useBean action itself but rather in something else nearby in the JSP source.


....my impression is that it can't interprete it 'cos it can't find the
thing and it can't find the thing 'cos it's relying on information in
another file which isn't correct.

The page translator -- which is where the error appears to occur -- does not need to find the class file for your bean. It simply uses the useBean attributes to produce some Java source code. If the class file is out of place then you should get a different error from a different component (details and timing depend on the servlet container).


                                  Example, here is the contents of my
myapp.xml file in conf\Catalina\localhost\

<Context path="/myapp" docBase="C:/jakarta-tomcat-5.0.28/webapps/myapp"
        debug="0" reloadable="true">

</Context>

As far as I can tell, this whole myapp.xml business is unnecessary with Tomcat 5. I don't know whether Tomcat does anything with that file at all if it is present. For the time being, I'd remove it altogether and see what happens; unless Tomcat starts having trouble finding your webapp, you can probably keep it gone.


...oh yeah, I get a bit confused with which way the obliques should go
as well (yes, I'm on Windows)!

The way you have put them should work.

Last thought, I've noticed that the jsp-examples don't seem to need any
of this stuff - maybe I'm chasing a red herring, even though it is
emphasised on one those Tomcat doc pages!

For which version of Tomcat? I don't see anything about it on the page I pointed you to, and it certainly ought to be there if the file is necessary.


--
John Bollinger
jobollin@xxxxxxxxxxx
.



Relevant Pages

  • Tomcat web application - using JAR
    ... The web application can call the Jar classes fine (I added the full ... JAR it throws a NoClassDefFoundError exception. ... I tried adding the classpath the WEB-INF/classes directory which seems ... Am I using external JARs with Tomcat the right way? ...
    (comp.lang.java.programmer)
  • tomcat jsp log4j partially working
    ... try to run that bean from a Tomcat JSP I only get the log messages to ... ROOT logger will output messages ...
    (comp.lang.java.programmer)
  • myjavaserver
    ... I've an account on myjavaserver and I'start to send my work. ... My problem is that in a page I use a bean, but tomcat can't find the class. ...
    (comp.lang.java.programmer)
  • Application scope variable on startup
    ... I have my own ResourceFactory which returns a bean. ... resource factory in tomcat 5.5 context xm file. ... I would like to create a application scope variable on tomcat startup ...
    (comp.lang.java.programmer)
  • Re: path problem in tomcat
    ... what i mean is if i attach a piece of code inside the bean, ... different with start tomcat from eclipse or start it directly. ...
    (comp.lang.java.programmer)