You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by David Ramsey <dr...@neko.com> on 2003/11/19 22:58:01 UTC

Using Java applets in a Turbine/Velocity webapp

I come from the application programming world. While at Apple, I was 
the author of MacPaint 2.0; I wrote a TV-in-your-computer application 
for the long-defunct Aapps Corp., and I spent 9 years working on 
various Mac and Windows interations of OmniPage at Caere/ScanSoft, 
before they discovered that programmers in the Ukraine were a lot 
cheaper than programmers over here.

So I'm used to controlling every pixel on the screen and having dynamic 
displays of information and although I've been doing webapps the last 3 
years or so, it's been a constant, background irritation that I was so 
much at the mercy of the limitations (and capricious interpretations 
thereof) of HTML.

And now I've got a situation where a user can start a rather lengthy 
process and I'd really, really like to display some real-time 
information about the progress of said process, without requiring the 
user to hit "refresh" or doing something lame like having the browser 
page auto-reload every 5 seconds.

The solution seemed obvious: use an applet. And wow, look, applets are 
pretty easy to write, and I'm not sure how I'll hit the database yet 
but hey, let's just get something going quickly here and see how it 
works and start designing all that chewy user interface goodness with a 
chocolate center.

The more experienced Turbine users out there are already starting to 
snicker, I know.

Over the past couple of days I've been going slowly insane trying to 
figure out how to use a Java applet in my Turbine/Velocity web 
application. In most browsers, the area for the Java applet is blank, 
generally with a red "X" or other indication of failure. A couple of 
browsers display an error message about a "bad magic number."

Searching the archives, I see this question has been asked several 
times before. Responses fall into three categories:

* No response at all-- this is the most common. This is disheartening.

* A suggestion that the error message indicates that the applet class 
or jar file is corrupted.

* A sarcastic comment that this mailing list is for Turbine and not 
client-side stuff like applets.

Well, the applet file isn't corrupted; it works fine in a simple 
hand-coded HTML page. Furthermore, the "bad magic number" error message 
seems to be pretty generic: I can change any attribute of  <applet> to 
a random string, and get the _same message_. And I used to complain 
about Mac OS error numbers, can you believe it?

Because I have faith, I refuse to believe (admittedly in the face of 
mounting evidence) that it's _impossible_ to use applets in a 
Turbine/Velocity application. If I hadn't methodically tried almost 
every directory in the webapp hierarchy, I'd think it was simply a 
matter of putting the applet files in the right place.

But damned if I can figure out what it is.

Somebody out there must have done this. Or know how to do this.



---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Using Java applets in a Turbine/Velocity webapp

Posted by Matt Hughes <mh...@uvic.ca>.
On Wed, 19 Nov 2003, David Ramsey wrote:

> And now I've got a situation where a user can start a rather lengthy
> process and I'd really, really like to display some real-time
> information about the progress of said process, without requiring the
> user to hit "refresh" or doing something lame like having the browser
> page auto-reload every 5 seconds.

Hello, I don't have any suggestions about the applet, but a I have a
suggestion for updating the broswer to display to indictate the progress
of a task.

Turbine has a nice XMLRPC server functionality, which you can use to
indicate the status of the process. You can send a javascript XMLRPC
client like the one by Jan-Klaas Kollhof (don't have a url sorry, google
him) to the broswer, which it could use to make xml rpc calls and then
update a progress bar implemented with W3 DOM or DHTML or whatever.

I use XMLRPC calls to refresh combo boxes, so I know the xmlrpc stuff
works for sure at least.

Matt Hughes
mhughe@uvic.ca



---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Using Java applets in a Turbine/Velocity webapp

Posted by David Ramsey <dr...@neko.com>.
I've been Googling like a fiend, but more couldn't hurt...:-(

I don't think Turbine per se has anything to do with it, either. I have 
tried the applet in a very simple HTML page, invoking it with the 
<applet> tag:

<HTML>
<HEAD>
<META HTTP-EQUIV = "Content-Type" CONTENT = "text/html; 
charset=iso-8859-1">
<TITLE>
Applet Test Page
</TITLE>
</HEAD>
<BODY>
test0.Applet1 will appear below in a Java enabled browser.<BR>
<APPLET CODEBASE = "Java%20Classes" CODE = "test0.Applet1.class" NAME = 
"TestApplet" HSPACE = "0" VSPACE = "0" ALIGN = "middle" WIDTH = "400" 
HEIGHT = "300">
</APPLET>
</BODY>
</HTML>

This works fine, with the "Java Classes" folder at the same directory 
level as the HTML file. I think the problem might be specifying _where_ 
the applet's files are; since the HTML is generated dynamically by 
Velocity, the concept of "the directory the web page lives in" might 
not apply to the folder the .vm files are in.

-- David

On Nov 19, 2003, at 5:24 PM, Blair Martin wrote:

>
>> Hm. Didn't seem to make any difference, but perhaps I misunderstood
>> what you mean by "the root of the web app". To me, this means the same
>> directory level as the WEB-INF folder. Is this correct?
>
> Yeah, that's what I meant. You know, I remember we had the same "bad 
> magic
> number" error when we were first playing around with this stuff.
> Unfortunately, that was well over a year ago and no one can seem to 
> remember
> how we solved it. It may have to do with the JVM version. Anyways, do a
> google search of applet AND "bad magic number" and you'll get tons of 
> hits.
> Maybe you can figure it out from there.
>
> And have you tested out your applet in a small, non-Turbine webapp? 
> Because
> I don't think Turbine has anything to do with it.
>
> Blair
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Using Java applets in a Turbine/Velocity webapp

Posted by Blair Martin <bl...@mindspring.com>.
> Hm. Didn't seem to make any difference, but perhaps I misunderstood
> what you mean by "the root of the web app". To me, this means the same
> directory level as the WEB-INF folder. Is this correct?

Yeah, that's what I meant. You know, I remember we had the same "bad magic
number" error when we were first playing around with this stuff.
Unfortunately, that was well over a year ago and no one can seem to remember
how we solved it. It may have to do with the JVM version. Anyways, do a
google search of applet AND "bad magic number" and you'll get tons of hits.
Maybe you can figure it out from there.

And have you tested out your applet in a small, non-Turbine webapp? Because
I don't think Turbine has anything to do with it.

Blair


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Using Java applets in a Turbine/Velocity webapp

Posted by David Ramsey <dr...@neko.com>.
Hm. Didn't seem to make any difference, but perhaps I misunderstood  
what you mean by "the root of the web app". To me, this means the same  
directory level as the WEB-INF folder. Is this correct? In other words:


MyWebApp
	|
	-----applet
	|		|
	|		---Applet1.class
	|
	-----WEB-INF
			|
			---lib
				 |
				 -----MyWebApp.jar

I'm also using JVM 1.4.1. I used the code you provided in my .vm file  
for the test page with the only alterations being the removal of the  
"archive" attribute and the replacement of "SelectApp" with "Applet1".

-- David Ramsey

P.S. Thanks to other respondents. I'm trying to stick with applets now,  
'cause I can use Swing and other GUI things I like. I've played with  
jsps a little and am ambivalent: it's cool to have Java directly in the  
web page, and how the heck do you debug complex pages without zillions  
of printlns?

On Nov 19, 2003, at 2:27 PM, Blair Martin wrote:

> Man, I know the frustration you're talking about. :)
>
> I don't know if your problem stems from the applet config information  
> in
> your HTML (template) or not but if it does this may help...
>
>
> <table border="0" cellspacing="0" cellpadding="0">
> <tr><td>
> <OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
>  WIDTH=420
>  HEIGHT=400
>  NAME="EnrollmentTree"
>
> codebase="http://java.sun.com/products/plugin/autodl/jinstall-1_4_0- 
> win.cab#
> Version=1,4,0,0">
> <PARAM NAME = CODE VALUE = "SelectApp.class" >
> <PARAM NAME = CODEBASE VALUE = "$content.getURI("applet/")" >
> <PARAM NAME = ARCHIVE VALUE = "p_v1.jar" >
> <PARAM NAME = MAYSCRIPT VALUE = true >
> <PARAM NAME="type" VALUE="application/x-java-applet;jpi-version=1.4">
> <PARAM NAME="scriptable" VALUE="true">
>
> <COMMENT>
> <EMBED type='application/x-java-applet;jpi-version=1.4'  width='420'
> height='400'
> pluginspage='http://java.sun.com/products/plugin/index.html#download'
> java_code='SelectApp.class'
> java_codebase='$content.getURI("applet/")'
> archive='p_v1.jar'
> name='EnrollmentTree'
> MAYSCRIPT='TRUE'
>>
> <NOEMBED>
> </COMMENT>
> This applet won't run in your browser.
> </NOEMBED></EMBED>
> </OBJECT>
> </td></tr>
> </table>
>
> I'm still using Turbine 2.1 (it works!) but I find it hard to believe  
> that a
> later version of Turbine is going to break this.
>
> My Java runtime version is 1.4.1. I've only tested this with IE 5.5  
> and 6.
>
> My applet code is in a directory "applet" in the root of the web app.  
> That
> directory contains my main applet class SelectApp and a jar file  
> "p_v1.jar"
> that contains third party libs used by the applet.
>
> I haven't looked at this for a while so I can't remember how I got all  
> this
> but it works. Hope it does for you, too.
>
>
> Blair Martin
>



---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Using Java applets in a Turbine/Velocity webapp

Posted by Blair Martin <bl...@mindspring.com>.
Man, I know the frustration you're talking about. :)

I don't know if your problem stems from the applet config information in
your HTML (template) or not but if it does this may help...


<table border="0" cellspacing="0" cellpadding="0">
<tr><td>
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
 WIDTH=420
 HEIGHT=400
 NAME="EnrollmentTree"

codebase="http://java.sun.com/products/plugin/autodl/jinstall-1_4_0-win.cab#
Version=1,4,0,0">
<PARAM NAME = CODE VALUE = "SelectApp.class" >
<PARAM NAME = CODEBASE VALUE = "$content.getURI("applet/")" >
<PARAM NAME = ARCHIVE VALUE = "p_v1.jar" >
<PARAM NAME = MAYSCRIPT VALUE = true >
<PARAM NAME="type" VALUE="application/x-java-applet;jpi-version=1.4">
<PARAM NAME="scriptable" VALUE="true">

<COMMENT>
<EMBED type='application/x-java-applet;jpi-version=1.4'  width='420'
height='400'
pluginspage='http://java.sun.com/products/plugin/index.html#download'
java_code='SelectApp.class'
java_codebase='$content.getURI("applet/")'
archive='p_v1.jar'
name='EnrollmentTree'
MAYSCRIPT='TRUE'
>
<NOEMBED>
</COMMENT>
This applet won't run in your browser.
</NOEMBED></EMBED>
</OBJECT>
</td></tr>
</table>

I'm still using Turbine 2.1 (it works!) but I find it hard to believe that a
later version of Turbine is going to break this.

My Java runtime version is 1.4.1. I've only tested this with IE 5.5 and 6.

My applet code is in a directory "applet" in the root of the web app. That
directory contains my main applet class SelectApp and a jar file "p_v1.jar"
that contains third party libs used by the applet.

I haven't looked at this for a while so I can't remember how I got all this
but it works. Hope it does for you, too.


Blair Martin


----- Original Message ----- 
From: "David Ramsey" <dr...@neko.com>
To: <tu...@jakarta.apache.org>
Sent: Wednesday, November 19, 2003 1:58 PM
Subject: Using Java applets in a Turbine/Velocity webapp


> I come from the application programming world. While at Apple, I was
> the author of MacPaint 2.0; I wrote a TV-in-your-computer application
> for the long-defunct Aapps Corp., and I spent 9 years working on
> various Mac and Windows interations of OmniPage at Caere/ScanSoft,
> before they discovered that programmers in the Ukraine were a lot
> cheaper than programmers over here.
>
> So I'm used to controlling every pixel on the screen and having dynamic
> displays of information and although I've been doing webapps the last 3
> years or so, it's been a constant, background irritation that I was so
> much at the mercy of the limitations (and capricious interpretations
> thereof) of HTML.
>
> And now I've got a situation where a user can start a rather lengthy
> process and I'd really, really like to display some real-time
> information about the progress of said process, without requiring the
> user to hit "refresh" or doing something lame like having the browser
> page auto-reload every 5 seconds.
>
> The solution seemed obvious: use an applet. And wow, look, applets are
> pretty easy to write, and I'm not sure how I'll hit the database yet
> but hey, let's just get something going quickly here and see how it
> works and start designing all that chewy user interface goodness with a
> chocolate center.
>
> The more experienced Turbine users out there are already starting to
> snicker, I know.
>
> Over the past couple of days I've been going slowly insane trying to
> figure out how to use a Java applet in my Turbine/Velocity web
> application. In most browsers, the area for the Java applet is blank,
> generally with a red "X" or other indication of failure. A couple of
> browsers display an error message about a "bad magic number."
>
> Searching the archives, I see this question has been asked several
> times before. Responses fall into three categories:
>
> * No response at all-- this is the most common. This is disheartening.
>
> * A suggestion that the error message indicates that the applet class
> or jar file is corrupted.
>
> * A sarcastic comment that this mailing list is for Turbine and not
> client-side stuff like applets.
>
> Well, the applet file isn't corrupted; it works fine in a simple
> hand-coded HTML page. Furthermore, the "bad magic number" error message
> seems to be pretty generic: I can change any attribute of  <applet> to
> a random string, and get the _same message_. And I used to complain
> about Mac OS error numbers, can you believe it?
>
> Because I have faith, I refuse to believe (admittedly in the face of
> mounting evidence) that it's _impossible_ to use applets in a
> Turbine/Velocity application. If I hadn't methodically tried almost
> every directory in the webapp hierarchy, I'd think it was simply a
> matter of putting the applet files in the right place.
>
> But damned if I can figure out what it is.
>
> Somebody out there must have done this. Or know how to do this.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


RE: Using Java applets in a Turbine/Velocity webapp

Posted by David Demner <tu...@demner.com>.
> The solution seemed obvious: use an applet. And wow, look, applets are

> 

Hi David,

I've never done this using an applet.  But I've done something similar
(albeit using .NET and asp).  The basic idea is that you have a jsp page

containing a servlet.  The servlet basically looks like this:

<%
HttpSession session = request.getSession(true);
Vector messages;
int currentIndex = 0;
while (session.getValue("MessagesPending").equalsIgnoreCase("true")) {
	messages = (Vector)session.getValue("MessageVector");
	while (currentIndex < messages.getSize()) {
		out(messages.get(i));
		currentIndex++;
	}
	Thread.sleep(1000);
}

while (currentIndex < messages.getSize()) {
	out(messages.get(i));
	currentIndex++;
}

out("Finished");
session.putValue("MessageVector", null);
%>


Then in your processing step, access the session, put your messages in 
the MessageVector, set the MessagesPending to true, and voila! Your 
messages print on the screen.

Or something like that.

Good luck,

David


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org