my dog learned polymorphism
The moose likes Servlets and the fly likes JSP's and class files..... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "JSP Watch "JSP New topic

JSP's and class files.....

Stone Golem

Joined: Oct 27, 2001
Posts: 8
Hi all... I've written and compiled java code and it's in the format of a .class file, but it doesn't really meet the standards set out for beans. I was wondering how I can have my jsp's use my getters and setters within my class files. I was wondering also if I need to put the class files in a certain directory, so that the jsp's can see the class files. (I'm using Tomcat!) I was playing a bit with the useBean tag, but I guess I'm a little bit of a greenhorn, as I have hit a roadblock.
Any help would be greatly appreciated.
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
Hi Stone,
Answering the second bit first ... there are a number of places in which the class files can be placed. The easiest place to put them while you are learning about JSPs is in a directory called "classes" underneath the WEB-INF directory of your web application.
The TOMCAT_HOME\webapps\examples directory is an example web application. A "web application" (or webapp) is essentially just a specific directory structure in which to place all of the resources that make up your web application. The JSP files generally sit at the top of the webapp (for example, directly under the examples directory), while the classes can sit under the WEB-INF\classes directory.
If you place your class files under the WEB-INF\classes directory, remember to create the appropriate directory structure to meet your package structure.
Once the JSP can see the classes, you just need to have the appropriate get and set methods for each property in your class. For example, if you have a property called name, you should gave methods called getName and setName respectively. Also, for your class to work properly with the <jsp:useBean/> tag, you should also have a default, no arguments constructor. This is (basically) what makes it a JavaBean.
Hope that helps...
Simon Brown
Co-author of Professional JSP 2nd Edition
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: JSP's and class files.....
It's not a secret anymore!