Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to read a value in applet from jsp

 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

I have the following code



the code is executing perfectly i.e.,

it is accessing the testapp.class and reproducing the gui which the testapp class has
it is printing the value of the absolute path ( from where the testapp.jsp is running)

now my question is how can i use the string ap( String ap= getServletContext().getRealPath("/"); in the above code) in my applet class so that i can tell where the property file is residing to the properties class.


thank you in advance
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"getServletContext().getRealPath" returns an absolute path that's valid on the server only - the applet wouldn't be able to make use of it.

Any path information the applet needs is best passed via an applet parameter as part of the <jsp:plugin> tag.
 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ulf,

do you mean to make use of codebase in jsp:plugin
i found that codebase is used to tell the exact location of the file.

"getServletContext().getRealPath" returns an absolute path that's valid on the server only - the applet wouldn't be able to make use of it.


i know that "getServletContext().getRealPath" returns an absolute path that's valid on the server only because i tried it in applet and it did not work.

so i passed its value to some String ap, and wanted to acces the value of ap in java code..

is that possible.
thank you

 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
codebase has nothing to do with passing parameters to applets; it's used for finding jar files that the applet needs.

Look for something that creates "param" tags inside of the jsp:plugin tag.

i know that "getServletContext().getRealPath" returns an absolute path that's valid on the server only because i tried it in applet and it did not work.

The reason it didn't work is that applets (rather obviously) don't have a servlet context.

so i passed its value to some String ap, and wanted to acces the value of ap in java code..

That's still no good because the path is a server path which has absolutely no meaning or applicability to an applet. Didn't we go over all this yesterday already?
 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ulf,

since ap is returning this i thought of using it from applet.


thank you
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I give up. Yesterday we talked at length about why it's not possible for applets to access the server file system. I had gotten the impression that you understood that; I won't go over all that again today.
 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ulf,

i understand. but i'm desperate to get the output.

since you said it is possible to write to property file from client which is in same machine as the server ( with signed applets or granting permissions in java policy) i was just trying what else i could do to get the output. i'm desperate.

thank you
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
since you said it is possible to write to property file from client which is in same machine as the server ( with signed applets or granting permissions in java policy)

Yes, and then you said that this will not be the case during deployment, since there will be multiple applet clients, none of which is running on the server. Which makes this approach useless. So you're trying exactly what we both agreed wouldn't work; I'd say that's a waste of time.
 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
yes, but hmm.

it's ok ulf
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic