关于Applet通过Servlet得到数据库中数据的问题

cenwenchuok 2002-04-01 03:46:31
写了一个Applet通过Servlet到数据库里去数据的程序,在servlet中只重载了一个get方法,现在通过在ie里面写入http://localhost:8080/CommunicationApp/servlet/serveletgetdata.ServletSQL?Select * from ServletDB中可以得到返回的结果,然而在Applet中写入一下一段代码却的不到结果,只是返回了这样的错误,请大家帮忙.
代码:
URL url = new URL ("http://10.8.23.44:8080/CommunicationApp/servletsql");
String StrSql = URLEncoder.encode( "StrSql" ) + "=" + URLEncoder.encode(Sql);

//String StrSql = "http://localhost:8080/CommunicationApp/servletsql?StrSql" + "=" + Sql;

URLConnection uc = url.openConnection();
uc.setDoOutput(true);
uc.setDoInput(true);
uc.setUseCaches( false );
uc.setRequestProperty("Content-type","application/x-www-form-urlencoded");

DataOutputStream dos = new DataOutputStream(uc.getOutputStream());
dos.writeBytes(StrSql);
dos.flush();
dos.close();

错误:
2002-04-01 15:35:15 - Ctx( /CommunicationApp ): 405 R( /CommunicationApp + /servletsql + null) HTTP method POST is not supported by this URL
...全文
37 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Netix 2002-04-02
  • 打赏
  • 举报
回复
去看看http://www.emapgo.com,
界面上有四个Applet,两个用于图形显示,两个显示文本信息。
所有的内容全部来自SQL Server数据库(包括图形和文字)。
idpmud 2002-04-01
  • 打赏
  • 举报
回复
把Servlet中的DOPOST方法重载,调用DoGET方法,这样就可以从根本上解决问题。
tonybin 2002-04-01
  • 打赏
  • 举报
回复
我看明出来了,你的strsql应除掉前面的urlpath,直接用StrSql="StrSql"+ "=" +URLEncoder.encode( Sql)
tonybin 2002-04-01
  • 打赏
  • 举报
回复
DoGet方法中要么直接在url中使用参数,要么用流写文件,不要两者同时使用.

81,122

社区成员

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

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