• Post Reply Bookmark Topic Watch Topic
  • New Topic

Method library

 
Tomas Nilson
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!
I am about to develop a homepage with a calendar function in html and JSP with a MySQL database. The server does not have support for Java Beans, which I intended to use (for the logic).
I only want to have to write the code that connects to the database and inserts and retrieves data from it once (of course), so I was wondering if it is a good idea to put these methods in a file and then import that file from all other jsp pages? Or is there a better way of doing this?
Thanks in advance,
Tomas
 
chanoch wiggers
Author
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was forced to deal with this once - yes, its probably best to import the functionality if you cant load your own classes onto the server. The only other option is to define the classes in your JSP at the top = before you include any JSP, you write the code for the class and it becomes an inner class of your JSP:
<%@ page import="blah,blah">
<%
public class JDBCAccessingClass {
public getStuffFromDatabase() {
// do it
}
}
then you can call this class like this:
KDBCAccessingClass myJDBC = new JDBCAccessingClass();
etc etc. The compiled servlet for the JSP is called something else everytime the JSP is compiled which means that any changes you make to the class will also be reflected in the resultant servlet.
so, (whew), the way to do it is probably to write seperate files that basically define your java beans for you and include them statically into the JSP. an ugly hack but if its the only option you have....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!