applet和servlet通讯的问题

xingxingliang 2003-05-19 05:57:39
我在applet中向servlet传送数据,想传给servet的doget()方法,
程序如下:

String serverURL;
//servlet的url,这样直接访问可以吗?
serverURL = getCodeBase()+"myPage/servlet/gisserver.DataServer";

output.setText("connect to: " + serverURL);

String queryString = query;
output.setText("Attempting to send:" + serverURL);

//建立与Servlet的联接,向Servelt传输数据
// Get the server URL
URL url = new URL(serverURL);

// Attempt to connect to the host
URLConnection con = url.openConnection();

// Initialize the connection
con.setDefaultUseCaches(false);
con.setUseCaches(false);
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
con.setRequestProperty("Content-length", String.valueOf(queryString.length()));

OutputStream out = con.getOutputStream();
out.write(queryString.getBytes());
out.flush();

但是在调用时,在applet控制台返回的出错信息如下,不知什么意思。请高手分析指教:

java.io.IOException: Server returned HTTP response code: 405 for URL: http://localhost/myPage/servlet/gisserver.DataServer

因为“405”信息说明是不正确的方法调用,小弟有几个疑问:
1.我用的服务器是apache+tomcat,这样向服务器的servlet传数据可以吗?
2.这些数据是通过doGet()方法响应吗?
3.到底哪里错了?

请高手指教,万分感谢,
如果搞定,随便多少分都送!
...全文
18 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xingxingliang 2003-05-19
  • 打赏
  • 举报
回复
这两个不对吗?好像没有问题吧,看到很多例子都这样的啊
yefc 2003-05-19
  • 打赏
  • 举报
回复
con.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
con.setRequestProperty("Content-length", String.valueOf(queryString.length()));


=======================================================

I guest some headers are missing.......

62,612

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧