wood burning stoves 2.0*
The moose likes Tomcat and the fly likes Deploying applets with tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Reply locked New topic
Author

Deploying applets with tomcat

Martin Richard
Greenhorn

Joined: Mar 23, 2005
Posts: 7
I am having trouble finding any tutorials on how to serve applets. Even using semi-idiot proof JBuilder I can't get it working. What is the normal procedure for deploying an applet on a Tomcat server? Where do they go? Are there any necessary web.xml entries for them? etc.
Jeffrey Spaulding
Ranch Hand

Joined: Jan 15, 2004
Posts: 149
Seems like you're barking up the wrong tree.

Tomcat is a Servlet Container, Applets are a client side thing. To deploy an applet you place the applet's class on a webserver and use a html page with the applet tag to reference it.

As soon as the client processes the page, the class is transferred to the client and runs there locally.

For example the folowing code in a htm page loads one of my favourite applets.



To see the effect goto http://www.durius.com


[ March 23, 2005: Message edited by: Jeffrey Spaulding ]
[ March 23, 2005: Message edited by: Jeffrey Spaulding ]
Martin Richard
Greenhorn

Joined: Mar 23, 2005
Posts: 7
I understand what an applet is I just can't figure out how to deploy applets in a JSP page. Do I need a seperate web server running and then have the applet tag refer to a class deployed on that server?
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
No separate web server is needed, as I recall placing an Applet in a JSP page is no different than a regular HMTL page. The applet's code is transferred to your system and executed by the browser's Java Virtual Machine (JVM). The Applet is enclosed in the Applet Tag
Jeffrey Spaulding
Ranch Hand

Joined: Jan 15, 2004
Posts: 149
You simply place the Jar File with the applet code in the webapps/[YourWebapp] path. This is regarded as the document root for all files referenced in the jsp page.

Imagine the applets jar just like an image or a pdf you want to serve.

Tomcat simply is the plain vanilla HTTP Server here. No J2EE magic included. (Except that Tomcat isnt really fast in serving files )

The rest is pure HTML, just like you would do it in an Apache or whatever.

J.
Martin Richard
Greenhorn

Joined: Mar 23, 2005
Posts: 7
Hmmm, I'm still having problems.

Here is how my files are setup

SessionTest/index.jsp
SessionTest/WEB-INF/classes/showdocumentapplet/ShowDocument.class

in index.jsp I have the following code:

<applet
codebase = "WEB-INF/classes"
code = "showdocumentapplet.ShowDocument.class"
name = "ShowDocument"
width = "400"
height = "300"
hspace = "0"
vspace = "0"
align = "middle"
>
</applet>


In file view of my IDE it works fine and loads the applet. However in web view or if I start the server the browser isn't finding the applet. the Tomcat server produces the following error:
StandardHost[localhost]: MAPPING configuration error for request URI

I am completely stuck and can't find any working samples in how to get this to work.
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
I believe Tomcat restricts directs access to WEB-INF folders and its contents.

Give this a try. Change your directory structure to ...
Jeffrey Spaulding
Ranch Hand

Joined: Jan 15, 2004
Posts: 149
As i said



You simply place the Jar File with the applet code in the webapps/[YourWebapp] path. This is regarded as the document root for all files referenced in the jsp page.


It really is that simple.

Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
And yes, you can also do what Jeffrey said:
You simply place the Jar File with the applet code in the webapps/[YourWebapp] path. This is regarded as the document root for all files referenced in the jsp page


Your directory structure would look like this ...


I hope this helps.
Martin Richard
Greenhorn

Joined: Mar 23, 2005
Posts: 7
Thanks a lot folks you have been a great help.
A Shehadi
Greenhorn

Joined: Jul 13, 2009
Posts: 19
Although I have read the forum for some time now, it's my first post. So hello everyone!

Ok, I have read this thread regarding applet deployment under Tomcat, but still can't get it to work. I have a Turbine project in /webapps/autos, and I need to embed an applet inside a Velocity page (which ultimately translates into a regular HTML page).

So I have put my ImageUploader.jar file under /webapps/autos, and I'm embedding it this way:



However, I get a "java.lang.ClassFormatError: Incompatible magic value 1008813135 in class file ImageUploaderApplet", which as far as I know and have read means that, since Tomcat can't find the applet, it's serving an error HTML page, such that the JVM tries to "interpret" it resulting in incompatible magic numbers, obviously because Java files and HTML are different.

Any pointers on how to embed a Java Applet in a Turbine dynamic page?

The thing is, I've read somewhere else that changes should be made inside the Tomcat config files, but the problem is I need to deploy the whole Turbine project as a War file into another server I have no config privileges in.

Thanks a lot!

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61653
    
  67

I suggest you post your question in the Applets forum as there really isn't any Tomcat issues. I cannot move this very old thread there so you'll have to repost your question.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Deploying applets with tomcat