[英]Sending parameter form applet to a servlet
我正在做一个程序,其中只能通过小程序访问用户数据。
在我的程序中,我想从小应用程序中获取数据(字符串参数),并希望从小应用程序中获取数据(字符串参数)。 但是我不知道为什么我的servlet没有被调用。 我正在使用GET方法。
在下面,我附上了我的代码。
我在其中调用servlet的Applet代码:
System.out.println("codebase"+getCodeBase());
URL postURL = new URL("http://localhost:8080/AppletExample/myServlet");
HttpURLConnection conn = (HttpURLConnection) postURL.openConnection();
conn.setRequestMethod("GET");
conn.setDoOutput(true);
conn.connect();
PrintWriter out = new PrintWriter(conn.getOutputStream());
out.write("param1="+alias);
out.flush();
Servlet代码为:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("name value is");
response.setContentType("text/html;charset=UTF-8");
String name=request.getParameter("param1");
System.out.println("name value is"+name);
}
请提供任何解决方案。
OutputStreamWriter out = new OutputStreamWriter(
conn.getOutputStream());
用您的代码替换上面的代码
PrintWriter out = new PrintWriter(conn.getOutputStream());
这可能有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.