applet communication using post method

送分小仙女□ 提交于 2019-12-19 04:47:08

问题


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");

回答1:


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



来源:https://stackoverflow.com/questions/2484119/applet-communication-using-post-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!