Tomcat

From Redbrick Wiki
Revision as of 03:31, 21 October 2007 by Receive (talk | contribs) (moved from old website)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

TomCat is an application server which supports the JSP and java servlet standards, read more about it at: http://jakarta.apache.org/tomcat/. To use tomcat on RedBrick you must mail the webmaster 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.