• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Properly adding a servlet and applet combination to a website

 
Xavi Villalta
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I recently tried to add a servlet and applet to my website, but the applet would not load.
I added the servlet and applet .class files to the server and made an html reference to the applet on the page.
All I got was a blank box with an "X" in the corner.

Is there anything that needs to be done to the classes before adding to the server?
And what happens to the servlet once uploaded? Does it continuously run on the server, or does it start up once the applet calls it the first time.

I'm using a free website from webs.com so I'm not entirely sure that servlets are supported.


Now why I try it on the localhost it isn't loading either. It worked the first time that I tried it, but now nothing. Just another blank box with an X.
I even trashed the files and re-unzipped the example file that worked the first time and added it to the web-apps directory, restarted tomcat and firefox, and nothing seems to be working now. I only added one line of code to the server.xml the first time (when it worked) if that makes any difference.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you set the content type appropriately for applets?
 
Xavi Villalta
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abimaran Kugathasan wrote:Did you set the content type appropriately for applets?


Yeah I set it to "application/x-java-serialized-object"
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Xavi Villalta wrote:Yeah I set it to "application/x-java-serialized-object"

Class files most definitely should not be served with that MIME type; it's for serialized Java objects, and it doesn't sound like you're using those. I've never had to fiddle with MIME types to get applets to work.

Post the APPLET tag from the HTML page, and the directory layout of all relevant directories.
 
Paul Clapham
Sheriff
Posts: 21558
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should also look at what you see in the Java console (in the browser) when your applet fails to load.

As for servlets, if you have free hosting then there's a very good chance your hosting company doesn't support them. Of course you should ask them to be sure, and to find out how they support them.

But you are already using Tomcat on your test machine, so you already know that you can't just send your servlets to the server. You know that you have to create an application and install it in the servlet container on the host using the container's standard deployment procedure, right?
 
Xavi Villalta
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay here are my responses and questions

1) Whenever the applet fails to load, nothing shows up in the console (and I mean nothing), but I guess that doesn't matter since there is other stuff wrong...
2)Yeah, I just found out that you have to have a certain file structure when making a web application, thank you for telling me that.
3) What do you mean by "installing" it? Before I was putting the example file under "webapps" and making a context statement in the server.xml (That worked fine only the first time) and then I would just go to "localhost:8080/echo/index.html".
4)What MIME type should I be using? "text/plain"? I'm either going to send a String[] back and forth between the applet and servlet or, if it's possible, a plain text file.

Thanks for the help

And here was the applet tag I was using:
<applet code="EchoApplet.class" width="500" height="200"></applet>
The directory was just the main directory with the applet class and the servlet class (along with other unimportant files), but I found out that was wrong...
 
Paul Clapham
Sheriff
Posts: 21558
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Xavi Villalta wrote:And here was the applet tag I was using:
<applet code="EchoApplet.class" width="500" height="200"></applet>

That should work if EchoApplet.class is in the same directory (on the server, of course) as the HTML file in which that element appears.
 
Xavi Villalta
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But doesn't a web application need to have a certain file structure to be able to work properly?
Or is the "WEB-INF" and "classes" folder structure only necessary for tomcat?

It also could be that the applet doesn't work properly because it won't show up in a browser for some reason...
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Classes used by servlets and JSPs go into WEB-INF/classes, but applets are run on the client (the browser) - that's a different JVM that shares no classes with the servlets.

What's more, nothing that's inside of WEB-INF will ever be served to the client, so the applet wouldn't be able to get at those classes.
 
Paul Clapham
Sheriff
Posts: 21558
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Xavi Villalta wrote:But doesn't a web application need to have a certain file structure to be able to work properly?
Or is the "WEB-INF" and "classes" folder structure only necessary for tomcat?


Well, yes, it does. But don't get confused between a web application and an applet. The two things are completely unrelated. Applets don't need a web application, you just put them into your site along with HTML. And conversely web applications don't need to include applets, in fact they usually don't.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic