applet里的方法:
private HttpURLConnection getConnection() throws IOException{
String url = " http://127.0.0.1:8080/Update/httpAutoUpdateServlet";
URL server = new URL(url );
HttpURLConnection connection = (HttpURLConnection) server.openConnection(); //获取服务器端连接
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setUseCaches(false);
connection.setInstanceFollowRedirects(false);
connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
return connection;
}private void sendServletObject(HttpURLConnection con, String path)
throws IOException {
ObjectOutputStream oos = new ObjectOutputStream(con.getOutputStream());
HashMap ht = new HashMap();
ht.put("name", "出来呀");
oos.writeObject(ht);
oos.flush();
oos.close();}private void UploadFile(String b)throws IOException{
HttpURLConnection con = this.getConnection();
con.connect();
sendServletObject(con, b);con.disconnect();
}
public void init(){
String fileName = "c:/a.jpg";
UploadFile(fileName);
}servlet里的方法:public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("gbk");
response.setContentType("text/html;charset=gbk");
PrintWriter out = response.getWriter();
ObjectInputStream ois = new ObjectInputStream(request.getInputStream());
System.out.println("==="+ois.read());
out.flush();
out.close();
}什么后台打出来的总是-1呀`