File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Tomcat and the fly likes How to deploy a Web Application in Apache Tomcat? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How to deploy a Web Application in Apache Tomcat?" Watch "How to deploy a Web Application in Apache Tomcat?" New topic

How to deploy a Web Application in Apache Tomcat?

Tanka Banerjee
Ranch Hand

Joined: Aug 16, 2006
Posts: 64
I am a SAP Master Data management guy.
But I have been assigned some Java J2EE work.
I need help.
I want to deploy a JSP Page in Apache Tomcat 5.5.26 Server.
The procedure I followed is:
I wrote a JSP :

helloworld.jsp :

Test JSP

<% String menuData = "Hi My JSP";

<jsp:plugin type="applet" code="InitHTMLForm.class" codebase="./WEB-INF/classes"
Unable to start plugin!


This JSP is embedding an Applet Code.

import java.util.Random;
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Font;
import java.awt.Event;
import java.awt.Button;
import java.awt.event.ActionListener;
import java.awt.Color;
import java.awt.FlowLayout;

public class InitHTMLForm extends Applet {

public void init()
setBackground(; // Set background color to blue.
setForeground(Color.white); // Set foreground color to white.
setLayout(new FlowLayout()); // Set flow style.

ActionListener l= null;;
Button b = new Button();


public boolean action (Event evt, Object arg) {
// Handle the actions of the window.
// Button hit
if ( instanceof Button) {
return true;
// Text field data entry

return false;

public void paint(Graphics g)
g.setFont(new Font("Helvetica", Font.PLAIN, 8));

g.drawString("Hello world!", 50, 25);


public void mouseClicked (Event e)
int c =e.clickCount;

public void getFirstName() {
// in real life, you have TextField in your Applet and
// you want to transert its content to the HTML FORM
// return myTextField.getText();

String axilleas = "ShutDown -l";

Windows will shutdown at 7 pm and the computer
will be closed. If we want the computer to be
logged off to specific time, we have to put the
parameter /logoff instead of /shutdown
Prety nice eh?
Runtime nikos = Runtime.getRuntime();

catch(IOException e)

The Applet is working fine with itself.
I have tested it. It logs off my Computer.

Now, the point is the JSP is failing to load the Applet in the web browser.

I have followed this deployment structure.
Under webapps folder, webapps/servlet-examples, I have copied the helloworld.jsp.
Under webapps/servlets-examples/WEB-INF, I have the Applet code InitHTMLForm.class.
The web.xml is under the webapps/servlets-examples/WEB-INF.

I have this structure of the web.xml:


I have html page called Test.html which is placed under

<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<body bgcolor="#FFFFFF">
<form name="myform" id="myform" method="post" action="abcd/helloworld">
<input type="Submit" value="Submit">

Now, my first problem I am unable to access the html page from internet browser:
It is giving page not found error: 404 but when I am accessing the JSP by giving:
It is loading up but the applet is not being loaded with ClassNotFoundException.
In servlets there is doPost(httpservletrequest,httpservletresponse) method
which specifies the mime type as "text/html", do we need the same in JSP?
Anyhow the html page should be accessed.
Please help me out.

Dawn Charangat
Ranch Hand

Joined: Apr 26, 2007
Posts: 249
create a folder named "abcd" in the tomcat/webapps folder. Inside abcd, make sure you have the WEB-INF folder and the web.xml configuration file [google its contents... its too much to just mention all here].

Place your JSP page inside abcd, and then start the server, and fire your URL.

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46337
Too difficult a question for us beginners. Moving.
Tanka Banerjee
Ranch Hand

Joined: Aug 16, 2006
Posts: 64
The problem is done.
Applets are treated as insecure entity by JVM.
So, first we have to jar the applet by jar -cvf applet.class.
Then, we have to create a policy file by some name "java.policy".
Then we have to create key value pair and sign the jar files.
Commands are:
keytool -genkey -alias TestApplet -validity 365
jarsigner InitHTMLForm.jar TestApplet

I agree. Here's the link:
subject: How to deploy a Web Application in Apache Tomcat?
jQuery in Action, 3rd edition