try something likeimport java.net.*;
import java.io.*; int x= 12;
int y= 20;
URL urlInfo = new URL("http://yourhost/jsp/somejsp.jsp");
HttpURLConnection connection = (HttpURLConnection)
urlInfo.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
PrintStream out = new PrintStream(connection.getOutputStream());
out.println("x="+x+"&y="+y);
out.close();
DataInputStream in =
new DataInputStream(connection.getInputStream());
String sIn = in.readLine();
in.close();
import java.io.*; int x= 12;
int y= 20;
URL urlInfo = new URL("http://yourhost/jsp/somejsp.jsp");
HttpURLConnection connection = (HttpURLConnection)
urlInfo.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
PrintStream out = new PrintStream(connection.getOutputStream());
out.println("x="+x+"&y="+y);
out.close();
DataInputStream in =
new DataInputStream(connection.getInputStream());
String sIn = in.readLine();
in.close();
String y = request.getParameter("y");int xx = Integer.parseInt(x);
int yy = Integer.parseInt(y);%>
<applet code="myokmap.class" archive="okmapCore.jar,jbcl.jar" height=550 VIEWASTEXT width="640">
</applet>
我想知道如果要做参数传递,还需要在插入APPLET的这句中加入传递的参数吗?如果要,是用什么样的语法?
而且在APPLET中,我希望在mousePressed事件中传递参数。
在线等待
<applet code="myokmap.class" archive="okmapCore.jar,jbcl.jar" height=550 VIEWASTEXT width="640">
</applet>
我想知道如果要做参数传递,还需要在插入APPLET的这句中加入传递的参数吗?如果要,是用什么样的语法?
而且在APPLET中,我希望在mousePressed事件中传递参数。在线等待中 解决了一定给分!!!
你的参数要提交到服务器端,
在按钮的事件处理程序中对带参数的get or post jsp文件,
<%String x = request.getParameter("x");
String y = request.getParameter("y");int xx = Integer.parseInt(x);
int yy = Integer.parseInt(y);%>
也只是静态的啊。
<%String x = request.getParameter("x");
String y = request.getParameter("y");int xx = Integer.parseInt(x);
int yy = Integer.parseInt(y);%>
也只是静态的啊。
如果我的APPLET的鼠标按下事件中这样定义:
public void mousePressed(MouseEvent e)
{
int x= e.getX();
int y= e.getY();
try{
URL urlInfo = new URL("http://127.0.0.1:8080/examples/myjsp.jsp");
HttpURLConnection connection = (HttpURLConnection) urlInfo.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
PrintStream out = new PrintStream(connection.getOutputStream());
out.println("x="+x+"&y="+y);
out.close();
DataInputStream in =new DataInputStream(connection.getInputStream());
String sIn = in.readLine();
in.close();
}catch(MalformedURLException u){
System.out.print("u.MalformedURLException" + u.getMessage());
}catch(IOException io){
System.out.print("io.IOException"+ io.getMessage());
}
}而我的JSP中这样定义:
<html>
<body>
<applet code="myApplet.class" height=550 VIEWASTEXT width="640">
</applet>
<%@ page language="java" import="java.lang.*" %>
<%
String x = request.getParameter("x");
String y = request.getParameter("y");
%>
<p>结果:<%=x%></p>
</body>
</html>
这样就能完成通信了吗?我的X,Y变量会随着鼠标点击而改变吗?