jsp help
[nobr]Hi,
I am trying to make a communication between a .jsp and a applet.
What I am trying to achieve is enter two numbers in the applet wich is embeded in the jsp, and then the .jsp will display those numbers.
what can I do to solve this?
thanks for any response...
this is my code:
snippet of the applet(the Sum.class):
public ArcControls(){
Button b =null;
add(s =new TextField("0", 4));
add(e =new TextField("0", 4));
b =new Button("Sum");
b.addActionListener(this);
add(b);
}
publicvoid actionPerformed(ActionEvent ev){
try{
URL url =new URL("http://localhost:81/5/test.jsp?param1" +s.getText()+"param2="+e.getText());
}
catch(MalformedURLException e){
}
}
snippet of the .jsp:
<form action="test.jsp" method="post">
Enter two numbers:
<b>
<br>
<APPLET CODE="Sum.class" WIDTH="300" HEIGHT="100"></APPLET>
</b>
<br><br>
<%
String var=request.getParameter("param1");
String var2=request.getParameter("param2");
out.println(var);
out.println(var2);
%>
</form>
[/nobr]
[2142 byte] By [
deroka] at [2007-11-27 5:38:15]

# 3
> URL("http://localhost:81/5/test.jsp?param1"
> +s.getText()+"param2="+e.getText());
One problem I see here is that you're not separating the parameters of the query string with an ampersand, they run together.
It should be:
URL("http://localhost:81/5/test.jsp?param1" +s.getText() +"¶m2="+e.getText());
Also, where are you submitting that page? Or is that part of the code not shown?
# 4
[nobr]> Also, where are you submitting that page? Or is that
> part of the code not shown?
I am using Blazix Web Server,
this is all the code I have(its still really small):
it's still not working...
what can I do?
test.jsp:
<html>
<head>
<title> Test </title>
</head>
<body>
<form action="test.jsp" method="post">
<center>
Enter two numbers:
<b>
<br>
<APPLET CODE="Sum.class" WIDTH="300" HEIGHT="100"></APPLET>
</b>
<br><br>
<%
String var=request.getParameter("param1");
String var2=request.getParameter("param2");
out.println(var);
out.println(var2);
%>
</center>
</form>
</body>
</html>
and the Sum.java
(this one generates two .class that are: Sum.class and ArcControls.class)
as you can see I am calling the Sum.class from the test.jsp.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.net.*;
public class Sum extends Applet {
ArcControls controls;
public void init() {
setLayout(new BorderLayout());
add("South", controls= new ArcControls());
}
public void start() {
controls.setEnabled(true);
}
public static void main(String args[]) {
Frame f = new Frame("Sum Program");
Sums = new Sum();
s.init();
s.start();
f.add("Center", s);
f.setSize(300, 100);
f.show();
}
}
class ArcControls extends Panel implements ActionListener{
TextField s;
TextField e;
public ArcControls() {
Button b = null;
add(s = new TextField("0", 4));
add(e = new TextField("0", 4));
b = new Button("Sum");
b.addActionListener(this);
add(b);
}
public void actionPerformed(ActionEvent ev) {
try{
URL url = new URL("http://localhost:81/5/test.jsp?param1" +s.getText()+"¶m2="+e.getText());
}
catch(MalformedURLException e){
}
}
}
[/nobr]
deroka at 2007-7-12 15:11:33 >

# 5
As far as I understand, the problem is because you want to display the numbers entered in the applet in the HTML form and you're trying to do that sending the numbers as parameters in a query string to the same page.
Now the stumbling block seems to be this; you're creating the URL, but you're never calling that page. So nothing happens. I've never worked with Applets so I don't know how to submit from there or how to call a page. But this seems to be the way out: http://www.geocities.com/gnashes30/java/tutorial/new_win.htm
Also, it seems to be me to be the wrong way of moving the data around, you're causing an extra call when you could use JavaScript to read the parameters from the Applet on the client-side. See this http://www.rgagnon.com/javadetails/java-0175.html