Tomcat

From Redbrick Wiki
Jump to navigation Jump to search
IMPORTANT: The content of this page is outdated. If you have checked or updated this page and found the content to be suitable, please remove this notice.

TomCat is an application server which supports the JSP and java servlet standards, read more about it at: http://jakarta.apache.org/tomcat/.

TomCat currently does not work on RedBrick. We're still trying to fix it.

Running TomCat on RedBrick

To use tomcat on RedBrick you must mail the webmaster/admins and ask for an account

How do I use Servlets ?

You may access your servlets via http://jakarta.redbrick.dcu.ie/~[username]/servlet/[ServletName]

How do I use JSP ?

Once you have access you can put JSP files anywhere at all in your public_html directory, just make sure to use the extension ".jsp", in lowercase. They will be accessible as part of your site.

Where do I put classes / jars / something.properties ?

All classes go in the ~/public_html/WEB-INF/classes/ directory, typically this is also where you put other types of files, such as ".properties" files. .jar files go in ~/public_html/WEB-INF/lib .

Note: if you add a jar file, before it can work your webapp context has to be reloaded. You'll have to get the webmaster to do this, try not to do it very often.

Can you give me some examples to get me started ?

yes, if the webmaster has done there job correctly, when you get access you should have a sample servlet and a sample JSP.

Servlet example:

You should have "HelloWorldExample.class , HelloWorldExample.java, LocalStrings.properties, LocalStrings_en.properties,  LocalStrings_es.properties" files in your ~/public_html/WEB-INF/classes directory.
HelloWorldExample.class is the actual class that provides the servlet, HelloWorldExample.java is the java source file used to create this class. If you read the java source you'll notice it uses the LocalStrings stuff, this requires the Localstrings files in your classes directory. This servlet can be accessed via: http://jakarta.redbrick.dcu.ie/~[username]/servlet/HelloWorldExample

Jsp example:

You will also find a date.jsp file placed in your ~/public_html/ directory, since it uses a class called dates.JspCalender we need to provide it. You'll notice there's a directory called "dates" in your ~/public_html/WEB-INF/classes/ directory which provides this class. This jsp may be accessed via: http://jakarta.redbrick.dcu.ie/~[username/date.jsp

Will all this work with https ?

yes.

Can I use an index.jsp file as the default file for a directory ?

yes.

I've heard that TomCat is insecure, what's that about ?

All JSP's and servlets run as the "jakarta" user, this means that you are sharing this username with other Tomcat users. There is the potential for abuse, but not much. Access to TomCat is given on a basis of trust, breaches of trust will be viewed seriously.

I want to use a servlet/jsp to write to a file, how do I do this ?

Because servlets and jsp run as the jakarta use any files you need to write to must be writable my the jakarta user. You can use an acl to achieve this, something like:"setfacl -rm u:jakarta:6 <filename>"

What Permissions should I use ?

All of your subdirectories in WEB-INF should be 755 (or "a+rx"), all of your classes,jars and jsp's should be 644 (or "a+r"). Accessing something in http://jakarta.redbrick.dcu.ie/~[username]/WEB-INF/ doesnt seem to work, what's wrong?

The webserver has been configured to deny all attempts at accessing the WEB-INF directory.

I want to log the remote IP, how can I?

Because of the way it works on redbrick, if you want to detect the remote IP address of the client you must use the alternative, direct , url. All you need do is change url's such as http://jakarta.redbrick.dcu.ie/~[username]/index.jsp to http://jakarta.redbrick.dcu.ie:8080/~[username]/index.jsp

Can I use advanced web.xml features such as URI remapping ?

Only if you use the direct form of the URL, as above. Add ":8080".

I forgot to add the classes and now my jsp/servlet wont work, how do I fix it ?

Tomcat wont try to reload your servlets or jsp's unless it has changed since the last time it accessed it. So if you forgot to add a set of classes that it needs, and it fails, just adding the classes wont be enough to fix it. You need to tell tomcat to refresh. You can do this by running: "touch [classname].class", in the same directory as the classes. After you do this, wait at least 15 seconds, and Tomcat will refresh your classes.

Running TomCat on a local Machine

Where do I start?

First off you'll need jakarta. If your in the CA labs this can be found on P\Projects\Web Servers\jakarta-tomcat-3.2.3 (This is the current version in the CA labs as of 23/2/2003).

How do I make Tomcat work?

There are a few variables you'll need to set up in order for tomcat to work. First off you'll need to set the variable JAVA_HOME to where ever your java folder is. E.g. if you were setting this up in the CA labs under Windows you'd need to type

set JAVA_HOME=C:\j2sdk1.4.0_01

You'll also need to set TOMCAT_HOME to where ever your jakarta folder is. E.g. in my CA account I have it at

H:\project\Servlet\jakarta-tomcat-3.2.3

Lastly you'll need to set up your CLASSPATH file to point to

TOMCAT_HOME\lib\servlet.jar

Is there no easier way?

I find it easier to put the above into the tomcat.bat file in jakarta-tomcat-3.2.3\bin, that way I don't have to remember to type them out everytime. Alternativly, you can just download my tomcat.bat file here

Note: This file might not work with other versions of tomcat, mine is 3.2.3. With other versions you may be best adding it youself.

How do I start Tomcat?

Now all you'll need to do is run TOMCAT_HOME\bin\startup.bat in Windows or TOMCAT_HOME\bin\startup.sh in UNIX and if you point a web browser at http://localhost:8080 You should see the default Tomcat webpage.

Anything else that will make my life easier?

There is other things you can do to files to make them more user friendly, the ones worth noting most are the servlet reloading without having to restart the server, and not having to put the :8080 at the end of localhost in your URL. To do this you can download my: server.xml and web.xml

Note: these are for the version of jakarta i'm using (3.2.3) and may not work with others.

To understand the changes i've made you're best of having a look at: http://www.moreservlets.com/Using-Tomcat-4.html#Configure-Tomcat