现在我尝试使用HttpURLConnection
但它不起作用,我不确定这是否正确。请建议谢谢。
// RequestDispatcher rd =
// request.getRequestDispatcher("http://192.168.1.2:8080/EEXAM/WindowsWordToHtmlServlet");
// rd.forward(request, response);
HttpURLConnection connection = null;
OutputStream os = null;
BufferedWriter writer = null;
try {
connection = (HttpURLConnection) new URL("/Servlet").openConnection();
connection.setReadTimeout(0);
connection.setConnectTimeout(0);
connection.setRequestMethod("POST");
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestProperty("Accept-Charset", CommonConstants.CHAR_ENCODING);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + CommonConstants.CHAR_ENCODING);
os = connection.getOutputStream();
writer = new BufferedWriter(new OutputStreamWriter(os, CommonConstants.CHAR_ENCODING));
writer.flush();
connection.getResponseCode();
} catch (Exception e) {
CustomLogger.error(e.getMessage(), e, request);
e.printStackTrace();
}