使用方法后Applet通讯 [英] applet communication using post method

查看:135
本文介绍了使用方法后Applet通讯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与servlet通信的小程序。我使用POST方法的servlet通信。我的问题是我怎么送参数给servlet。使用GET方法,这是相当简单的(我只是参数追加到之后的网址?)。但是,使用POST方法我怎么发的参数,这样在servlet的一面,我可以使用下面的语句:

 消息= req.getParameter(味精);

在该applet的一面,我建立POST方法连接如下:

 网​​址URL =新的URL(获得codeBase的()的servlet);
URLConnection的CON = url.openConnection();con.setDoInput(真);
con.setDoOutput(真);
con.setUseCaches(假);
con.setRequestProperty(内容类型,应用程序/八位字节流);


解决方案

首先,你需要调用(像你一样):

  urlConnection.setDoOutput(真);

然后获得的OutputStream

  OutputStreamWriter出=新OutputStreamWriter(urlConnection.getOutputStream());

和写入数据:

  out.write(paramName配置=+ paramValue);

在servlet中,你可以叫的request.getParameter(paramName配置)

可以在这里找到更多的细节和说明

I have an applet that is communicating with a servlet. I am communicating with the servlet using POST method. My problem is how do I send parameters to the servlet. Using GET method, this is fairly simple ( I just append the parameters to the URL after a ?). But using POST method how do I send the parameters, so that in the servlet side, I can use the statement :

message = req.getParameter("msg"); 

In the applet side, I establish POST method connection as follows :

URL url = new URL(getCodeBase(), "servlet");
URLConnection con = url.openConnection();

con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
con.setRequestProperty("Content-Type","application/octet-stream");

解决方案

First, you need to call (as you did):

urlConnection.setDoOutput(true);

Then obtain the OutputStream:

OutputStreamWriter out = new OutputStreamWriter(urlConnection.getOutputStream());

and write to it:

out.write("paramName=" + paramValue);

In the servlet, you can call request.getParameter("paramName")

More details and instructions can be found here

这篇关于使用方法后Applet通讯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆