aspose file tools*
The moose likes Applets and the fly likes posting back to applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "posting back to applet" Watch "posting back to applet" New topic
Author

posting back to applet

Gareth M
Greenhorn

Joined: Nov 16, 2004
Posts: 5
Hi All. Do any of you guys know how to send a value back to an applet once it has submitted data to a script page, viz. asp -(via a url submission from applet). Basically a search is done (on the asp script) and if a match is found the asp page will return one of three integers. What I'd like to do is retrieve the value from the asp page and send it back to the applet. Is this even possible?

Thank you in advance.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

HTTP is a response-request protocol. You request a URL, send along your data and you get some response back. That response in your case is the ASP page. Have it indicate the value somehow and parse it out in your applet. Check out the Java Tutorial chapter on Working with URLs for some examples.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Gareth M
Greenhorn

Joined: Nov 16, 2004
Posts: 5
I apologise for the (probably) stupid question but how do you get a response back from the HTML protocol? Using GET?

Thank you again
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

Did you follow the link I posted? I think the page titled Reading Directly From A URL would have explained that.
Some definitions you will find helpful:
HTML = Hypertext Markup Language = a way to encode information
HTTP = Hypertext Transfer Protocol = a set of rules about how HTML (among other things) are requested from a server and retrieved by a client.
Gareth M
Greenhorn

Joined: Nov 16, 2004
Posts: 5
Hi Joe,
I did follow the link and I am familiar with the definitions you've posted
I've become frustrated (with my own ineptness) that's why I posted again because I'm getting access denied messages in the status bar of my browser.

It seems so simple, but being a relative newbie at Java is what's frustrating me cos I've started Java again after doing other programming languages.

Thank you again for replying. I sincerely appreciate your time and effort.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

Originally posted by Gareth Miller:

I've become frustrated (with my own ineptness) that's why I posted again because I'm getting access denied messages in the status bar of my browser.


What are you getting in the Java console (Tools->SunJavaConsole)? Are you using URL/URLConnection to do the post or are you using AppletContext.showDocument? The latter won't work for what you want to do. You will also want to make sure your ASP page returns something sensible (i.e. some text if the mime type is set to text).
Gareth M
Greenhorn

Joined: Nov 16, 2004
Posts: 5
This is the part that works fine (post the value to the asp page)
try
{
URL url = new URL( pageName );
AppletContext context = getAppletContext();
context.showDocument( url );
}
where pagename is the fully qualified url

The part that was to receive the value back from that asp page was:

URL yahoo = new URL("http://***/");
BufferedReader in = new BufferedReader(
new InputStreamReader(
yahoo.openStream()));

String inputLine;
while ((inputLine = in.readLine()) != null)
getGraphics().drawString(inputLine,10,10);

in.close();

I've removed the URL for posting and replaced it with *(excuse me if I'm stating the obvious)

With ASP I could use XMLHTTP but Java has presented me with a whole new set of challenges.

I'll read up on Applets again this evening to ensure that that is not where the problem is. Man, I wish I could go back to Hello World programs like in first year ( so many years ago)
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

Your code does not do what you think it does. This code:

tells the browser to navigate to the given URL. That is, away from the page with your applet. It won't even be around to execute the later code. Maybe you should read that link I posted again. Specifically, the page titled
Reading from and Writing to a URLConnection.
Gareth M
Greenhorn

Joined: Nov 16, 2004
Posts: 5
Hi Joe

I cannot thank you enough for pointing out the errors in my code. I think I'm on the right track now. At least I can say I've learnt from my mistakes (with your help) It's so frustrating picking up a language again after not having to do it for so long.

Thanks again, and I'm sure it's not the last time I use this forum
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: posting back to applet