Jevan
[ free music, drawings, writing and more ]

image of a bridge

IT - JSP

The following are two sample files which specify and comprise a simple servlet for resin, that will put two pet type names into a list and then print the list through the java web server.

resin-3.0.22\webapps\test\WEB-INF\web.xml

resin-3.0.22\webapps\test\WEB-INF\classes\example\TestThree.java


The following is a simple example of a java database servlet:

resin-3.0.22\webapps\test\WEB-INF\classes\example\MySqlOneResin-java.html

The following is a slightly more advanced java database servlet. It fetches specific columns from the database (eg into variables of java types int, float, String). Also the entire 'test2' folder has been made into a "war" (web application archive) file so it is also available as test2.war which can be deployed into the resin database system just by placing the test2.war file in G:\Program Files\Server Applications\resin-3.0.22\webapps\ , when resin finds test2.war it will extract it to G:\Program Files\Server Applications\resin-3.0.22\webapps\test2\WEB-INF\ (including the web.xml file and the MySqlTwoResin.java file into the appropriate directories under test2\WEB-INF\).

The "war" file was created with the command 'jar cvf test2.war WEB-INF' which was run from a cmd.exe window while in the directory G:\Program Files\Server Applications\resin-3.0.22\webapps\test2\

resin-3.0.22\webapps\test2\WEB-INF\classes\example\MySqlTwoResin-java.html
test2-war.zip


To run the java database, place mysql-connector-java-3.1.14-bin.jar in G:\Program Files\Server Applications\resin-3.0.22\webapps\WEB-INF\lib and there's a tip - if resin will not compile it, try running the following batch file, located in resin-3.0.22\webapps\test\WEB-INF\classes\example\ (ie the same folder as the MySqlOneResin.java file):

doCompile.bat

"G:\Program Files\Java\jdk1.5.0_10\bin\javac" -classpath "G:\data\java\classes\mysql-connector-java-3.1.14-bin.jar;G:\Program Files\Server Applications\resin-3.0.22\lib\resin.jar" MySqlOneResin.java
pause

You may need to put C: instead of G: and replace the path shown with your resin path. The data\java\classes is just a place where the JConnector jar file has been stored, it doesn't matter the location (as long as it's specified in the CLASSPATH)

The CLASSPATH used in this example (control panel, system, advanced, environment variables) is:

G:\Data\Java\classes\mysql-connector-java-3.1.14-bin.jar;.


An image showing the java database website being accessed, which illustrates the results of accessing MySqlOneResin.java from the browser, this displays the "user" table of mysql, which for storing usernames and sql command permissions:

Screendump of example mysqloneresin - accessing a mysql database from java using resin web server