Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / June 2005

Tip: Looking for answers? Try searching our database.

passing param to an applet

Thread view: 
Frances Del Rio - 19 Jun 2005 19:55 GMT
I'm passing a param to an applet (running applet in a jsp and passing a
param from form..) put code in applet so if text field in form is empty
(such as when jsp first loads..) applet prints a specified string,
however it just prints "null"..  why is this..

in jsp:
  <APPLET code="Palindrome.class"width=500 height=100>
  <param name=color value="<%=ipt%>">   <!-- (from form..)  -->
  </APPLET>

in applet:
   public void paint(Graphics screen) {
     String theColor = getParameter("color");
       screen.setFont(f);
       screen.setColor(Color.red);
     screen.drawString("a string....", 100,20);
     if (theColor != null) {
  screen.drawString(theColor, 60,70);

 // *********** why is following stmt ignored.. *******
    } else if (theColor == null || theColor.equals("")) {
 //  } else if (theColor == null) {
     screen.drawString("field empty", 60,70);
    }

thank you.....

    Frances
Andrew Thompson - 20 Jun 2005 00:39 GMT
> I'm passing a param to an applet ..

URL?

> (running applet in a jsp and passing a param from form..)

URL?
(does any of this sound familiar?)

>..put code in applet so if text field in form is empty
> (such as when jsp first loads..) applet prints a specified string,
[quoted text clipped - 4 lines]
>    <param name=color value="<%=ipt%>">   <!-- (from form..)  -->
>    </APPLET>

--> HTML

   <APPLET code="Palindrome.class"width=500 height=100>
   <param name=color value="null">   <!-- (from form..)  -->
   </APPLET>

Look at the source of the final web page - I suspect
that (above) is what it reads.

Try instead..
   <APPLET code="Palindrome.class"width=500 height=100>
<%
 if (ipt!=null) out.print( "<param name='color' value='" + ipt + "'>" );
%>
   </APPLET>

HTH

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Frances Del Rio - 20 Jun 2005 04:09 GMT
>>I'm passing a param to an applet ..
>
> URL?

shucks, Andrew... that's right, I forgot url.. uploaded file and
everything for this post then forgot to include url....;)
http://www.francesdelrio.com/chat

to see jsp code pls see
http://www.francesdelrio.com/chat/index.zip
.......
>>..put code in applet so if text field in form is empty
>>(such as when jsp first loads..) applet prints a specified string,
[quoted text clipped - 20 lines]
> %>
>     </APPLET>

I put this code inside <applet> tag, like you said, but still same
problem (applet prints "null" when page first loads (and input field in
form is empty..)
I did correct that typo in <applet> tag (hours ago... but well, main
problem I have w/applets also is that it's so hard to get them to
reload.. esp Netscape, I'm finding it practically impossible to get them
to reload in FF/M/N..) thank you Andrew...  Frances
Andrew Thompson - 20 Jun 2005 10:07 GMT
>>>I'm passing a param to an applet ..
...
> http://www.francesdelrio.com/chat

Now *that's* what I'm talking about (constantly).

It does seem to support my first guesses though.

When I first visited the page, I 'Viewed Source' to observe..

<object classid="java:Palindrome.class" width=500 height=100>
<param name=color value="null">
</object>  

..The .JSP *is* writing null to the final HTML output.

If the user then sets focus to the form field and presses
'enter' with no data, the source then looks like this..

<APPLET code="Palindrome.class" width=500 height=100>
<param name=color value="">
<param name='color' value=''>
</APPLET>  

..wait a second!  Why is the 'color' attribute listed twice?

ba-Bing!

Guessing again - I suppose I should unzip your zip to
confirm it[1] but *now* it seems you have introduced the
way I suggested to write the applet element, while retaining
the original line as well.  Take out the original line
you had and include *only* the line I suggested.

* but I am evil, so I won't bother.

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Frances Del Rio - 21 Jun 2005 14:03 GMT
>>>>I'm passing a param to an applet ..
>
[quoted text clipped - 25 lines]
>
> ba-Bing!

ba-Bing indeed....;)  I had not realized you had meant take that other
line out... man, it works!! I get no "null" now if field is empty..
however, how does this work, Andrew, we say if param!=null print param,
but we don't say what to do if param==null, so I'm wondering how it is
that now I don't get 'null' when page first loads (& whenever form is
submitted w/empty field..) and why this only works if param tag is
surrounded by jsp code...  thank you Andrew...  gosh I'm starting to
work on a somewhat serious applet project, I better learn applets well
or else..  I do have a lot to learn here and well, a day at a time, as
they say... :)   thank you again.. Frances

> Guessing again - I suppose I should unzip your zip to
> confirm it[1] but *now* it seems you have introduced the
[quoted text clipped - 3 lines]
>
> * but I am evil, so I won't bother.
Andrew Thompson - 21 Jun 2005 15:11 GMT
>>>>>I'm passing a param to an applet ..
>>>http://www.francesdelrio.com/chat

>> ..The .JSP *is* writing null to the final HTML output.
..
> ba-Bing indeed....;)  I had not realized you had meant take that other
> line out... man, it works!! I get no "null" now if field is empty..
> however, how does this work, Andrew, we say if param!=null print param,
> but we don't say what to do if param==null,

(from earlier)
>     <APPLET code="Palindrome.class"width=500 height=100>
> <%
>   if (ipt!=null) out.print( "<param name='color' value='" + ipt + "'>" );
....
      (ipt!=null)
      ^ this part tests if ipt exists, if it does..
                  out.print( .. )
                  ^
                 ..is invoked which prints ..
                              "<param name='color' value='" + ipt + "'>"
                              ^
                              ..this string to the final web page.

>...so I'm wondering how it is
> that now I don't get 'null' when page first loads

You're testing for null in the applet, but I do not quite understand,
the page as it exists the last moment I checked has different text for
these two situations.  When the page is first visited,
ipt is null so no 'color' param is written to the applet element.
The applet should get a 'null' when it calls for the color parameter,
and your applet code checks for 'null' and prints no string.
(That is the behaviour I am observing at the moment, now if
I click the..

..Actually I just noticed something a little suspicious in your page and
got the validator to check it.

<http://validator.w3.org/check?uri=http%3A%2F%2Fwww.francesdelrio.com%2Fchat%2F>

It has 8 HTML parsing errors.

These HTML parsing errors generally only affect how a page *looks*,
but the problem is this.  If a browser is going to follow any logic
to rendering or constructing a page, it will use the HTML as a guide.
If the HTML is illogical, then all bets are off as to what assumptions
the browser's rendering angine will make in order to try and formulate
a complete web page.

In this page, some of the errors are to do with the nesting
of HTML comments, which is rather problematic since you have
an applet call using the <object> element commented out.

Does your page render the <applet> or the <object>?

It is hard to say if the browser is invoking the object
element, since
- it is commented out, but..
- using invalid HTML that the browser may or may not render.

So.  Before we speculate further about how this page behaves,
I suggest you create a veresion that
- validates according to the W3C recommendations
- removes all the JS (most things that can be done dynamically
with JS can be created statically in HTML, and it reduces the
number of complications and contributing factors.
- strips the page to the bare minimum - no CSS or styles
- removes the commented parts of the page[1] *unless* they actually
serve to explain what is happening.

[1]  Especially that <object> element.  I noticed that while the
<applet> element is not getting the parameter written, the <object>
element *is*.  Unreliable rendering of the page could explain all
other inconsistencies.

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Frances Del Rio - 21 Jun 2005 15:43 GMT
>>>>>>I'm passing a param to an applet ..
>>>>
[quoted text clipped - 41 lines]
>
> <http://validator.w3.org/check?uri=http%3A%2F%2Fwww.francesdelrio.com%2Fchat%2F>

Andrew, first of all, thank you very much for your help..
pg validates fine now..
http://validator.w3.org/check?uri=http%3A%2F%2Fwww.francesdelrio.com%2Fchat%2F

I had lots of stuff there commented out, took it out.. (found that jsp's
ignore <object> tag (which might be a problem down the line, but well,
one thing at a time..) but had left it there just in case (was commented
out.. now took it out..)

also reason was wondering why it was working even if param==null is that
I DIDN'T provide for that condition in applet (I had before, but it was
being ignored..) however now I added it back and now it prints one
string if param==null and param if param!=null..  I have this in applet now:

  if (theColor != null) {
  screen.drawString(theColor + " (param passed from form)", 60,70);
} else if (theColor == null || theColor.equals("")) {
   screen.drawString("field empty (nothing passed from form..)", 60,70);
}

and now it's working just as I wanted it to...:)
(I still would like to know why I had to surround <param> tag inside
<applet> tag w/jsp code..

why does this work..

  <APPLET code="Palindrome.class" width=500 height=100>
<%
  if (ipt != null) out.print("<param name='color' value='" + ipt + "'>");
%>
</APPLET>

but not this..

  <APPLET code="Palindrome.class" width=500 height=100>
<param name="color" value="<%=ipt%>")
</APPLET>

again, many thanks Andrew...  Frances
Andrew Thompson - 21 Jun 2005 19:33 GMT
(Sometimes I feel overwhelmed by the sheer volume of your
questions, so I have chosen to trim down your post to a
small part and attempt to explain that..)

> why does this work..
>
[quoted text clipped - 9 lines]
> <param name="color" value="<%=ipt%>")
> </APPLET>

OK.  Rather than tell you directly, I will try and give
you a few tips and debugging techniques.

The first is [1] 'look at the OUTPUT very closely'.
In this case, you need to look at the text that ends up
in the webpage in the browser itself.

If you are using IE, to view the source[2] you type
(menu shortcuts) alt V | S.

[2] The ability to delve directly into the code of
web pages (view the source), follow the links to pull
up external stylesheets or Javascripts as might be
related, is very handy.  Especially once you start dealing
with web applications that produce HTML.  You need
to see exactly what the browser is seeing - as opposed
to what you -expect- the browser to be getting.

At this point I need to hear from you specifically
(OK - words to the effect of..)
'Yes, I am viewing the source as it appears in the browser..'

Now, generate the .jsp page both ways and tell me *exactly*
what the differences are between the two applet elements as
they appear in the *browser*.

[ If you cannot spot the difference, copy/paste* both applet
elements and we will look at them here.. ]

* And just in case there is any doubt.  'copy/paste' does not
mean 'carefully retype' - it means _copy_ from the page and
_paste_ to the news message.

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Frances Del Rio - 21 Jun 2005 23:04 GMT
> (Sometimes I feel overwhelmed by the sheer volume of your
> questions, so I have chosen to trim down your post to a
> small part and attempt to explain that..)

gosh, sorry, will try to "trim" my questions in the future...  I do
appreciate yr help..

.........

> OK.  Rather than tell you directly, I will try and give
> you a few tips and debugging techniques.
[quoted text clipped - 17 lines]
> (OK - words to the effect of..)
> 'Yes, I am viewing the source as it appears in the browser..'

I do know what u mean re viewing source code generated by jsp, I do it
all the time (of course this is a very necessary tool when debugging
server programs..)

ok, on this page, http://www.francesdelrio.com/chat/index.jsp

this is how applet appears when I view source code GENERATED by jsp:

<APPLET code="Palindrome.class" width=500 height=100>

</APPLET>

applet tag in jsp itself:

<APPLET code="Palindrome.class" width=500 height=100>
<%
  if (ipt != null) out.print("<param name='color' value='" + ipt + "'>");
%>
</APPLET>

if, however, I do this in jsp:

<APPLET code="Palindrome.class" width=500 height=100>
<param name="color" value="<%=ipt%>">
</APPLET>

this is how generated code looks like:

<APPLET code="Palindrome.class" width=500 height=100>
<param name="color" value="null">
</APPLET>

(which is here:
ok, on this page, http://www.francesdelrio.com/chat/index2.jsp

so:  touchee.........  ;)
ok, so lesson here is what exactly.. (everytime I write something here I
have to go back and erase it b/c I realize I'm wrong..)  not sure..
surrounding <param> tag with jsp code difference is we have the
conditional, which we don't have in the plain HTML..  but well, still a
bit confused.. I thought HTML <param> tag was just to pass param from
jsp to applet, then in applet you would process to see if it's empty or
not..  but what do I know.........;)  Andrew, again, thanks a million
for yr help..  this applet project probably will drive me a bit nuts
before I'm done w/it.. (I saw an old post of yrs the other day, where
you and were talking about applets, you said "applets, the devil's
work.."  I remember that every time I'm having a hard w/an applet...;)

Frances

(a friend of mine is going to Sydney for a year, I'm jealous!..)

> Now, generate the .jsp page both ways and tell me *exactly*
> what the differences are between the two applet elements as
[quoted text clipped - 6 lines]
> mean 'carefully retype' - it means _copy_ from the page and
> _paste_ to the news message.
Andrew Thompson - 22 Jun 2005 05:27 GMT
>> (Sometimes I feel overwhelmed by the sheer volume of your
>> questions, so I have chosen to trim down your post to a
>> small part and attempt to explain that..)
>
> gosh, sorry, will try to "trim" my questions in the future...  I do
> appreciate yr help..

..perhaps one or two at a time?

> I do know what u mean re viewing source code generated by jsp,

Good!  I wanted to check.

Sometimes I will advise you to ignore the JSP for the moment and
be looking at or copy/pasting the HTML in the browser.

>..I do it
> all the time (of course this is a very necessary tool when debugging
> server programs..)

Sorry, despite reading your posts, I still could not be sure.
I may have just missed a reference to it..

> ok, on this page, http://www.francesdelrio.com/chat/index.jsp
>
[quoted text clipped - 3 lines]
>
> </APPLET>

(...snip JSP part)

> <APPLET code="Palindrome.class" width=500 height=100>
> <param name="color" value="null">
> </APPLET>
..

OK - so imagine (for a moment) that these two pages
are HTML - no JSP in the site.

Do you now understand why the second applet call results in false here..

if ( getParameter(color)!=null ) //results in false  
if ("null"==null) // results in false

?

Are we OK on the applet side?

> so:  touchee.........  ;)
> ok, so lesson here is what exactly..

We are not finished yet, but one of the concepts I
am trying to get across is to attempt to separate the .JSP
from the applet for a moment.  Looking at the problem in two
parts reduces its complexity, and reduces the uncertainty.

>..(everytime I write something here I
> have to go back and erase it b/c I realize I'm wrong..)  not sure..
> surrounding <param> tag with jsp code difference is we have the
> conditional, which we don't have in the plain HTML..  

Going back to something I put earlier..

>   if (ipt!=null) out.print( "<param name='color' value='" + ipt + "'>" );
....
      (ipt!=null)
      ^ this part tests if ipt exists, if it does..
                  out.print( .. )
                  ^
                 ..is invoked which prints ..
...

..but join the dots Frances.  What will happen in this code if
(ipt==null).  If ipt is 'null' What will print as a result of that line?

> ..this applet project probably will drive me a bit nuts
> before I'm done w/it.. (I saw an old post of yrs the other day, where
> you and were talking about applets, you said "applets, the devil's
> work.."  I remember that every time I'm having a hard w/an applet...;)

(chuckle)

> (a friend of mine is going to Sydney for a year, I'm jealous!..)

Lucky friend!  I hope they have a great time in Sydney..
Tell them to look me up if they want to go for a beer
with 'some weird guy from usenet'.

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Frances Del Rio - 22 Jun 2005 14:32 GMT
>>>(Sometimes I feel overwhelmed by the sheer volume of your
>>>questions, so I have chosen to trim down your post to a
[quoted text clipped - 74 lines]
> ..but join the dots Frances.  What will happen in this code if
> (ipt==null).  If ipt is 'null' What will print as a result of that line?

ok, as it stands right here..  I just did it just like that in applet..
 it prints nothing...  (before I did <param> tag the way you said in
jsp it was printing 'null'..  I was reading in a java book last night
that best way to grab params in an applet is in init() method, so will
also try that tonight when I get home..  also found yr page you referred
that frustrated and angry guy to ;)  very useful
(http://www.physci.org/codes/javafaq.jsp#appfirst) will read that too..
 Andrew, I won't take up any more of yr time w/this, thank you again so
much for your help...

(btw, I had just been wondering how do you comm. betw. a servlet and an
applet.. sooner or later I will want to do that but well, again, a day
at a time....:)

Frances

>>..this applet project probably will drive me a bit nuts
>>before I'm done w/it.. (I saw an old post of yrs the other day, where
[quoted text clipped - 8 lines]
> Tell them to look me up if they want to go for a beer
> with 'some weird guy from usenet'.
Andrew Thompson - 22 Jun 2005 15:45 GMT
> (btw, I had just been wondering how do you comm. betw. a servlet and an
> applet.. sooner or later I will want to do that but well, again, a day
> at a time....:)

(chuckle) That's the way to go.

Later.

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Frances Del Rio - 25 Jun 2005 21:42 GMT
>>(btw, I had just been wondering how do you comm. betw. a servlet and an
>>applet.. sooner or later I will want to do that but well, again, a day
[quoted text clipped - 3 lines]
>
> Later.

Andrew, I don't know if you'll see this, given we kind of killed this
thread, and I'm almost embarrassed to say but...  NOW I GET IT...  re
enclosing the <param> tag in that jsp.. ONLY purpose is the
conditional...  see I'm such a dork I had thought at first that
conditional was to print or not print VALUE of param, then of course I
realized it's to print <param> tag itself.. so of course this is why I
got nothing if param==null as that case <param> tag is not printed at
all..  again, am very grateful for all your help..  embarrassingly
so...;)...    Frances
Andrew Thompson - 26 Jun 2005 01:53 GMT
(much technical discussion)
..
>...  NOW I GET IT...

:-)   I was hoping it would 'click'.

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.