【求助万能的csdn】android客户端传递一个类到服务器端的问题?

现在是希望将android客户端生成的Device类传到服务器端处理,Device类已经实现了serializable类。
android端:

public static void upload(String url_path, Device d) {
try {
URL url = new URL(url_path);

HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("connection", "keep-alive");
conn.setRequestProperty("Charsert", "UTF-8");
conn.setReadTimeout(2000);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
OutputStream out = conn.getOutputStream();
//GZIPOutputStream gzipout = new GZIPOutputStream(out);
ObjectOutputStream O_out = new ObjectOutputStream(out);
O_out.writeObject(d);
System.out.println(url_path + d.getDescribes()); //此处可以输出,可是
//gzipout.finish(); //服务器端没有收到请求。
O_out.flush();
O_out.close();
out.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

}

url路径没问题。

服务器端:
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    System.out.println("--post--");
    InputStream in = request.getInputStream();
    //GZIPInputStream Gin = new GZIPInputStream(in);
    ObjectInputStream O_in = new ObjectInputStream(in);
    try {
        Device device = (Device) O_in.readObject();
        List<Object> list = new ArrayList<Object>();
        list.add(device.getId());
        list.add(device.getType());
        list.add(device.getSize());
        list.add(device.getDescribes());
        String sql = "insert into device values(?,?,?,?)";
        if(ju.updateByPreparedStatement(sql, list)) {
            System.out.println("上传完成!");
        }
    } catch (ClassNotFoundException | SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.out.println("上传错误");
    }
}

如果有请求,服务器端应该输出“--post--”,很明显服务器没有收到android的请求
请问这代码错在哪呢?还有要如何实现类的传输?这段代码对吗?谢谢!

response.getOutputStream.write("--post--");

如果write不行,就试试response.getOutputStream.println("--post--");

调试下,看看服务器收到的请求是什么,或者客户端根本就是有问题的。

你先用浏览器试一下,看看servlet关联上没。直接在浏览器中请求应该能显示post