• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Jsp--Applet

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I am working with an Applet/Jsp.
The applet only has two Texfield and a Boton.
First, i am calling the applet from a .jsp with this tag:

so, when i call the .jsp from the browser, it displays the applet with no problem.
As you can see i am calling another jsp(result.jsp), so that when i enter two numbers or letters,etc.. in the Texfields in the applet, this .jsp will receive those parameters and print them in screen.

The problem is that right now is like: there is no comunication, because when I press the button nothing happens.

is this the right way to do it?
what can i do?

the jsps:






[ May 06, 2007: Message edited by: Jack Bolton ]
[ May 06, 2007: Message edited by: Jack Bolton ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, this is not the right way to do it. Fields in applets are not part of the web page or any of its forms. While it's possible to achieve some limited communication between an applet and the web page it's on (using a technology called LiveConnect), I would advise against using that.

But the applet can instruct the browser to replace the web page with a different one, via the getAppletContext().showDocument(String URL) call. That URL can include the two field values as GET parameters.
 
Jack Bolton
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ulf Dittmer:

But the applet can instruct the browser to replace the web page with a different one, via the getAppletContext().showDocument(String URL) call. That URL can include the two field values as GET parameters.



in don't undesrstand well what you said.
Do you have examples?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's say the parameter are names param1 and param2, and you want to submit to http://www.server.com/myApp/myServlet. The code to do this would be:

where 'applet' is a reference to the applet object (which you can leave out if this code is part of the Applet class).
[ May 07, 2007: Message edited by: Ulf Dittmer ]
 
Jack Bolton
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working with Blazix Web Server to do this.
This is my applet class.
I am only working with the two .jsps and this class.
Where should I "insert" the code you posted?

 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the "actionPerformed" method, because that's the one that gets called when you click the button. And since that's not the one extending Applet, you'll need to pass a reference to the Sum class in the constructor.
[ May 08, 2007: Message edited by: Ulf Dittmer ]
 
Jack Bolton
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am declaring like this:


and i get: "unreported exception java.net.MalformedURLException; must be caught or declared to be thrown"

what should i do?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A number of things could go wrong when trying to access an URL, which is why that statement can throw an exception. Surround the statement with a try/catch block, and within the catch, somehow alert the user that there was a problem.
 
Jack Bolton
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok,
I declared it like this:



but two things I don't understand:
1. in the code you posted:


what "param1" and "param2" represent?

and 2.

Originally posted by Ulf Dittmer:
And since that's not the one extending Applet, you'll need to pass a reference to the Sum class in the constructor.



do you mean I have to make a reference of the actionPerformed method in the main method of the Sum class?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

try{
URL url = new URL("http://localhost:81/5/test.jsp" +s.getText()+e.getText());

}
catch(MalformedURLException e){

}



It is generally not a good idea to ignore exceptions, and definitely not here.

URL url = new URL("http://www.server.com/myApp/myServlet?param1=" +textfield1.getText()+"¶m2="+textfield2.getText());

what "param1" and "param2" represent?


You can choose those freely - whatever makes sense for your server program. But the server app will need to know what they are so it can access them. The JSP page can't use "s.getText" (which you have above), instead it needs to access the request object and get those parameter. To do that, it needs to know their names.

do you mean I have to make a reference of the actionPerformed method in the main method of the Sum class?


No. The actionPerformed method is in the ArcControls class, and that's where it is used. But that part of the code is already in place, so you don't need to worry about it.

It's a bit strange to have an applet with a main method, but I'm assuming you're aware of the differences between applets and applications.
 
Jack Bolton
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ulf Dittmer:
You can choose those freely - whatever makes sense for your server program. But the server app will need to know what they are so it can access them. The JSP page can't use "s.getText" (which you have above), instead it needs to access the request object and get those parameter. To do that, it needs to know their names.



give me a code example of this please...
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

give me a code example of this please...



Um, example for what? The various snippets I posted contain just about everything you'd need to make this work. Is there something in particular you're having trouble with?
[ May 20, 2007: Message edited by: Ulf Dittmer ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic