aspose file tools*
The moose likes Applets and the fly likes Applet in J2EE application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Applet in J2EE application" Watch "Applet in J2EE application" New topic
Author

Applet in J2EE application

Fahim Farook
Greenhorn

Joined: Mar 20, 2011
Posts: 12
Hi!
I have a J2EE project(AE) in tomcat/webapps/.
And an Applet (in WEB-INF/classes/applet package) which communicates with a servlet in the WEB-INF/classes/com/course/web folder (i.e. com.course.web package).
Since WEB-INF folder cannot be accessed by the browser, I added complied class files in applet package into a folder named "applet" under project folder. (i.e. tomcat/webapps/AE/applet)
In my project folder I created a testApplet.html file with <APPLET ..> tag which loads the applet.

Once I run the web server and visit to http://localhost:8080/AE/testApplet.html, I can see the applet GUI.
But this applet doesn't communicate with the Servlet.

In my applet, there are two combo boxes.
When I select an item from the first combo box, the applet should communicate with the servlet and fill the second combo box with related items.

The action listener for the first combo box is as follows.


I feel the problem is with the deployment of the applet.
OR - Is the method I used to communicate with the servlet wrong?
Your help is highly appreciated!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42913
    
  68
If you have problems with the communication part, I'd start by not ignoring all the I/O exceptions. Print a stack trace to the Java Console so that you know if/when an exception occurs.
Fahim Farook
Greenhorn

Joined: Mar 20, 2011
Posts: 12
Yes Ulf Dittmer,
Im using NetBeans IDE and since Its a Web Application, I cannot see the printStackStrace(). (no consoles are there in web applications???).

So I added a text area in the applet got the exceptions printed there.
Yes, it throws an exception at connection = getUrl.openConnection();
and its a FileNotFoundException (cought by a new catch(Exception e) block at the end),
with the error message
"java.io.FileNotFoundException : http//localhost:8080/AE/Search.do?searchEntity=Courses"

But Search.do is already deployed and I have overridden its doGet method.
Fahim Farook
Greenhorn

Joined: Mar 20, 2011
Posts: 12
Ulf Dittmer, I could figure out the problem.
In the Search servlet I was dispatching the out put to a JSP.
But I must have written the result object as follows.



Than you for your help!
Is there any better way to deploy an Applet in the web server rather than copying the Applet class files directly to the project folder?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

A hint for the future: orange text on a tan background is rather unreadable.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42913
    
  68
since Its a Web Application, I cannot see the printStackStrace(). (no consoles are there in web applications???).

The Java Console it always available. Check the Java Plugin control panel (or some such name) for related settings; maybe the Console is set to not be shown ever.
Fahim Farook
Greenhorn

Joined: Mar 20, 2011
Posts: 12
I got the java console running. Enabling Java Console

But now I got a new problem with a newer version of this applet.
From the servelet I'm writing a University object into output stream, instead of a String array.
The University class implements java.io.Serializable interface.

When I was reading the input stream from the applet, I got a ClassDefinitionNotFoundException .
I think its because I copied only the compiled applet package in to the document base/ Project folder, but the University class is in WEB-INF/classes/com.university package.
So I copied the entire com folder (compiled classes) into the project folder and then didn't receive ClassDefinitionNotFoundException .

But now I'm receiving a ClassCastException at


And also a java.io.IOException: Server returned HTTP response code: 500 on top of the stack trace.

How can I workaround this problem? Is there any neat way to deploy an applet on a web server rather than copying all
the classes into the project folder (from WEB-INF) when an applet needs those class definitions.?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42913
    
  68
A response code of 500 means that an error occurred on the server side; you'll need to check the server log files to figure out what happened.

Serializing objects between two JVMs generally only works if both sides use the same Java version, e.g. 1.6.0; is that the case? Even having (for example) 1.6.0_22 on one side, and 1.6.0_24 on the other could lead to problems.
Fahim Farook
Greenhorn

Joined: Mar 20, 2011
Posts: 12
Serializing objects between two JVMs generally only works if both sides use the same Java version, e.g. 1.6.0; is that the case? Even having (for example) 1.6.0_22 on one side, and 1.6.0_24 on the other could lead to problems.

I'm running the server on my local machine. But if I publish the application on another server and if the client JVM is of a different version, client cannot communicate with the server? If so, what is the solution? How can I sent an object to the client without serializing?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42913
    
  68
But if I publish the application on another server and if the client JVM is of a different version, client cannot communicate with the server?

They can communicate, but if they use binary serialization (the kind that uses Object[In|Out]putStream) then it's likely that there will be problems.

How can I sent an object to the client without serializing?

You can't, but you can use other forms of serialization that are not as brittle as binary serialization. For example, the java.beans.XMLEncoder and XMLDecoder classes offer XML serialization that *is* compatible across JVM versions. It requires the objects to follow JavaBeans conventions, though.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Applet in J2EE application