This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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
Author

How to deploy a Web Application in Apache Tomcat?

Tanka Banerjee
Ranch Hand

Joined: Aug 16, 2006
Posts: 64
Hi,
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 :

<html>
<title>
Test JSP
</title>

<body>
<% String menuData = "Hi My JSP";
%>

<jsp:plugin type="applet" code="InitHTMLForm.class" codebase="./WEB-INF/classes"
width="250"
height="50"
jreversion="1.5.0_15"
>
<jsp:fallback>
Unable to start plugin!
</jsp:fallback>

</jsp:plugin>
</body>
</html>

This JSP is embedding an Applet Code.

import java.io.IOException;
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(Color.blue); // 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();
add(b);
b.addActionListener(l);

}

public boolean action (Event evt, Object arg) {
// Handle the actions of the window.
// Button hit
if (evt.target instanceof Button) {
getFirstName();
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;
System.out.print(c);
getFirstName();
}

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();
try
{

nikos.exec(axilleas);
}
catch(IOException e)
{
System.out.println(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:

<web-app>
<servlet>
<servlet-name>helloworld.jsp</servlet-name>
<servlet-class>helloworld.jsp</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>helloworld.jsp</servlet-name>
<url-pattern>/abcd/helloworld</url-pattern>
</servlet-mapping>
</web-app>

I have html page called Test.html which is placed under
/webapps/servlet-exapmles/


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

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

Now, my first problem I am unable to access the html page from internet browser:
http://localhost:8080/abcd/helloworld
It is giving page not found error: 404 but when I am accessing the JSP by giving:
http://localhost:8080/servlets-examples/helloworld.jsp
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.

Regards
Tanka
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
Sheriff

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

Joined: Aug 16, 2006
Posts: 64
Hi,
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

Regards
Tanka
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to deploy a Web Application in Apache Tomcat?