servlet hosting logo
Contact us: +44 (0) 1491 413606 - contact@nameonthe.net
Members of
Members of Nominet Ripe member WorldPay Guarantee
We accept the following payment methods:
Visa payments supported by WorldPay Visa/Delta payments supported by WorldPay Visa/Electron payments supported by WorldPay Mastercard payments supported by WorldPay Switch payments supported by WorldPay JCB Solo payments supported by WorldPay
Servlets FAQ
This document contains common servlet hosting questions.
What version of Tomcat/JDK is running
The policy is to run the latest stable Tomcat version. As of writing (16/08/2006) this is Tomcat 5.5.15 and the Sun Microsystems JDK 1.5.0_3. However, you are freely able to change the JDK and Tomcat versions used within your account.
Where do need to put my jsp files for them to work?
When you have an account setup you can place your .jsp files in the root directory of your application. Note, the WEB-INF folder is automatically created for you and contains files which are not directly accessible, do not place jsp files in this directory unless you are using internal redirects (Using RequestDispatcher).

Whey does Tomcat say "No Context configured to process this request" when I upload a new application?
This is because has failed to deploy your application, the logs will offer an indication of why this occurred. The first place to look is within catalina.out within the TOMCATHOME/logs directory.

Where do I put my classes for servlets?
Classes which have been successfully compiled and adhere to the servlet spectification will need to be placed in your WEB-INF folder/classes folder. The Tomcat classloader looks for class files in the /WEB-INF/classes folder and jar files need to be placed in the /WEB-INF/lib folder. It is possible to place .jar files within the TOMCATHOME/common/lib directory which makes them globally available to all running webapps.

What url do I need to use to see my servlets in action?

If you have not specified any special mapping in your deployment descriptor file (/WEB-INF/web.xml) then servlets which you have placed in your /WEB-INF/classes folder will be visible from the following URL:

http://yourdomains/servlet/servletclassname

If you have packaged your servlets, for example in /WEB-INF/classes/com/mycompany/myservlet with the servlet source file having a 'package com.mycompany;' declaration then the servlet will be visible from the following url:

http://yourdomains/servlet/com.mycompany.myserlvet

Can I change the path to my servlet,i.e. this /servlet/com.mycompany.myservlet stuff is ugly?
To make these changes you will need to edit your deployment descriptor file (/WEB-INF/web.xml) and create a servlet mapping. Typically this will look something like this:

   <servlet>
    <servlet-name>myservlet</servlet-name>
    <servlet-class>com.mycompany.myserlvet</servlet-name>
   </servlet>
  
   <servlet-mapping>
    <servlet-name>myservlet</servlet-name>
    <url-pattern>/mypattern</url-pattern>
   </servlet-mapping>

Will changes to my web.xml be automatically recognised?
Yes, the latest versions of Tomcat support the detection of changes in the web.xml and will reload your application. However, under normal conditions Tomcat will mark your application as unavailable if it fails to re-deploy which requires a Tomcat restart.

What happens when I recompile my servlet, will it be automatically recognised?
The default setup for servlet accounts is for the reloadable flag to be set to true which means servlet classes will automatically be reloaded. There is a minor performance overhead with this approach, if you require this to be turned off please make a request to support at
Support

Can I use the javamail package to send email?
Yes, this package will in your classpath, for the transport properties use 127.0.0.1 for the host and port 25. A fragment of very basic code (no comments) using javamail can be seen below:

import java.util.Properties;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.Message;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.InternetAddress;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class SendmailServlet extends HttpServlet {

  public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
    Properties props = new Properties();
    props.put("mail.smtp.host", "127.0.0.1");
    Session s = Session.getDefaultInstance(props,null);
    try {
      MimeMessage message = new MimeMessage(s);
      InternetAddress from = new InternetAddress("test@nameonthe.net");
      message.setFrom(from);
      InternetAddress to = new InternetAddress("james@nameonthe.net");
      message.addRecipient(Message.RecipientType.TO, to);
      message.setSubject("Test mail");
      message.setText("Mail test");
      Transport.send(message);
    } catch (Exception e) {
      e.printStackTrace();
    }
    res.sendRedirect("/sentmail.jsp");
  }
}
Will I need to add database drivers into my classpath?
Yes, this gives the application developer the choice of driver to use.

Why does 'load data' using mysql fail?
The mysql developers decided that to do this the file being imported needs to readable by all, clearly this is not appropriate. Furthermore, because the login shell's are chrooted there is no reliable way for a user to determine where their environment sits within the file system. To solve this issue, the 'local' switch should be deployed, for a exhaustive explanation please visit the mysql documentation: http://www.mysql.com/doc/en/LOAD_DATA.html

Can I use the Jikes (IBM) compiler to compile my jsps?
Yes, the
Jikes compiler has key advantages over the Sun implementation, one of which being superior compilation performance. Note, only private JVM account holders can currently use Jikes. To configure Tomcat to user Jikes, edit the web.xml within /usr/tomcat/conf and search for 'jikes'. Full documentation can be found within the comments of the web.xml file.

Can I use the struts framework for my web application?
Yes, struts is a framework used for creating a web application with a MVC (Model View Controller) architecture. It is distributed as a jar file which you can place in your /WEB-INF/lib directory to use this framework . See
Apache Struts for detailed information including a user's guide.

Can I use Spring/Hibernate
Yes, we place no restrictions on the types of Java libraries that can be made available to your application, the only requirement is they are compliant .jar files.

Can I view my web application's logs?
Yes, although some advise that System.err or System.out are not used for logging, it is recommended to use the log function within the servlet class (
apidocs here). Alternatively, using the JDK's built in logging mechanism or a log kit such as log4j may be more desirable as they offer variable logging levels (debug,fatal,etc).

Whey does Tomcat create an empty directory when I deploy my .war file
Tomcat has experienced a fatal error when attempting to unpack the .war file, inspect the logs files to determine the nature of the cause.

Can I view my web application's work directory?
The work directory is where Tomcat places the source code to the servlet during the jsp to servlet translation process. Being able to view these proves invaluable when viewing stack traces caused by jsps throwing Exceptions. If the following stack trace head was being observed:

java.lang.NullPointerException
	at org.apache.jsp.index_jsp._jspService(index_jsp.java:111)
   
The developer can locate the file index_jsp.java within the TOMCATHOME/work/[context]/ directory and view line 111 and identify the nature of the problem.

I want to write a file to disk and need to know my path, how do I determine the full path of my web space?
To determine where your application lives for purposes of saving files use
getServletContext().getRealPath("/").

Can I deploy my application using a war file?
Yes, create a war file and rename it ROOT.war and place in the root directory of your web space. Tomcat will then deploy it.

Can I create new contexts under my domain name?
Yes, create a war file and upload into the root directory of your web space. The filename of the war file is instrumental in determining the name of the new context. For example, if you upload a war file with the filename myapp.war then Tomcat will deploy this application under the following name http://youdomain/myapp/.

I'm using French characters and my database returns them as '?', what am I doing wrong?
Invariably you need to ask support to change the character set your database is using, ASCII by default supports a relatively small number of characters.

Can I have Tomcat running in a headless environment?
If you are seeing errors such as this

Exception in thread "main" java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.

then it is very likely that you are using java.awt.* packages or the Swing packages. As the JRE runs within an Windowless environment the JRE is attempting to use (and failing) the native windowing apis (X in the case). Starting Tomcat with the 'headless' option allows you to use these classes.

Do I have any control over the server.xml, for instance I want to enable connection pooling
Yes, you have full control over the server.xml.

I want to take advantage of cascading with the database, so deleting a record causes all foreign references to be deleted
To ensure referential integrity database developers employ primary and foreign keys to ensure related tables maintain their integrity. As an example, two tables representing an employer and employee will often have a foreign key in the employee table which references the primary key in the employer table. An application developer can then use the foreign key in the employee table to locate the record in the employer table to identify who employs him/her. Attempts to delete the employer record when employee records are still referencing the record will cause the database to throw an error (as it should as it's maintaining referential integrity). In some circumstances this may not be desirable, so deleting employer records will cause all referencing records in the employee table to be deleted. The mechanism is 'on delete cascade'. An example of how to create this relationship is shown below:

CREATE TABLE employer(employer_id INT PRIMARY KEY,
name VARCHAR(100))

CREATE TABLE employee(employee_id INT PRIMARY KEY,
employer_id INT,
name VARCHAR(100),
CONSTRAINT employer_id_fk FOREIGN KEY(employer_id) REFERENCES employer(employer_id) ON DELETE CASCADE

Clearly, the employer_id field in the employee table references the employer_id field in the employer table. Deletions of employers will result in all related records in the employee table to be automatically deleted.

username
password
>> Login <<
Latest Java news
System Status
(Fri Mar 12 09:58:47 GMT 2010)
There are no known network or server problems

Valid XHTML 1.0!

Valid CSS!

Copyright © www.nameonthe.net 1999-2008, All Rights Reserved
All prices exclude VAT