シリアル化されたオブジェクトを Java クラスからサーブレットに送信し、そこでサーブレットがオブジェクトを取得してファイルとして保存したいと考えています。HttpURLConnection を使用してサーブレットに POST リクエストを送信する必要があることは認識していますが、以下のコードが正しいかどうかはわかりません。
private static HttpURLConnection urlCon;
private static ObjectOutputStream out;
public static void main(String[] args) {
    Names names = new Names();
    names.setName("ABC");
    names.setPlace("Bangalore");
    URL url;
    try {
        url = new URL("http://localhost:6080/HttpClientSerializable/HttpPostServlet");
    try {
        out = (ObjectOutputStream) urlCon.getOutputStream();
        out.writeObject(names);
        urlCon = (HttpURLConnection) url.openConnection();
        urlCon.setRequestMethod("POST");
        urlCon.setDoOutput(true);
        out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        } catch (MalformedURLException e1) {
            e1.printStackTrace();
        }
}
サーブレットには、次のコードがあります。
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ObjectInputStream in = new ObjectInputStream(request.getInputStream());
        try {
            names = (Names) in.readObject();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        in.close();
        ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("C:/Documents and Settings/RAGASTH/Desktop/Names"));
        out.writeObject(names);
        out.close();
    }
機能させるにはどうすればよいですか?また、サーブレットが受信したオブジェクトを応答として送り返すようにします。
どんな助けでも大歓迎です。ありがとう!