protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
URL url = new URL("http://localhost:8080/testy/Out");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
PrintWriter out = response.getWriter();
for(Enumeration e = request.getHeaderNames(); e.hasMoreElements();) {
Object o = e.nextElement();
String value = request.getHeader(o.toString());
out.println(o + "--is--" + value + "<br>");
connection.setRequestProperty((String) o, value);
}
connection.connect();
}
上記のコードをサーブレットに記述して、このサーブレットとは別の場所にフォームを投稿しましたが、機能していません。connection.setRequestPropertyを使用して、サーブレットへの着信リクエストのヘッダーフィールドを設定しても問題ありません。