请教各位一个关于applet 与 servlet相互通信的一个问题!(很急)

temphan 2002-04-16 03:57:18
找了一个applet与servlet通信的例子。
编译没有问题。运行时applet无法连接到servlet

servlet的路径没有问题,applet放在d盘的根目录下。
运行时显示:
java.io.IoException :Server Return HTTP response code:405 for URL........

程序如下所示!!!!!!!!!!

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ProcessDemo extends HttpServlet
{
public void doGet(HttpServletRequest req,
HttpServletResponse resp)
throws IOException, ServletException
{
System.out.println("1234");
DataInputStream in = new DataInputStream(req.getInputStream());
resp.setContentType("application/octest-stream");
ByteArrayOutputStream byteout = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(byteout);
String response = in.readUTF();
out.writeUTF(response);
out.flush();
byte buf[]= byteout.toByteArray();
resp.setContentLength(buf.length);
ServletOutputStream servletout = resp.getOutputStream();
servletout.write(buf);
servletout.close();

} // end dopost

}//end servlet


import java.io.*;
import java.applet.Applet;
import java.awt.*;

public class ProcessApplet extends Applet
{
String response;
public void init(){

try{
System.out.println("1234");
java.net.URL url = new java.net.URL("http://127.0.0.1:8080/servlet/ProcessDemo");
java.net.URLConnection con = url.openConnection();

con.setUseCaches(true);
con.setDoOutput(true);
con.setDoInput(true);
ByteArrayOutputStream byteout = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(byteout);
out.writeUTF("hello world!");
out.flush();
byte buf[] = byteout.toByteArray();
con.setRequestProperty("Content-type","application/octest-stream");
con.setRequestProperty("Content-length",""+buf.length);
DataOutputStream dataout = new DataOutputStream(con.getOutputStream());
dataout.write(buf);
dataout.flush();
dataout.close();

DataInputStream in = new DataInputStream(con.getInputStream());
response = in.readUTF();
System.out.println("read from server :" + response);
in.close();
}
catch(Exception e){
e.printStackTrace();
}

}

public void paint(Graphics g){
g.drawString("read from server :" + response,10,20);

}
}


...全文
4 点赞 收藏 4
写回复
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
whyyy78 2002-04-16
总得有个web服务器吧,把applet和相关的类放到服务器上。
回复
salute 2002-04-16
java.io.IoException :Server Return HTTP response code:405 for URL........
完整的是什么?
回复
temphan 2002-04-16
焦急的等待中,没有人知道吗?

回复
temphan 2002-04-16
等待中,很急啊,没有人知道吗?
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告