西风古道

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

服务器端:

@RequestMapping("/obtainUser")
public voidobtainUser(Integer uid, HttpServletResponse response)
            throws IOException {
       //假设一用户实例
        User user = userService.get(uid); 
     
        ObjectOutputStream objstream = new ObjectOutputStream(response.getOutputStream());
        objstream.writeObject(user);
        objstream.flush();
}        

applet端:

使用这种方式时,需要将远程获取的POJO类一同打包

private User obtainRemoteUser(Integer uid){
URL url = new URL(getCodeBase(),"/obtainUser?uid=" + uid + ""); URLConnection conn = url.openConnection(); conn.setUseCaches(false);
conn.setRequestProperty("Cookie", "JSESSIONID="+sid); //使用firefox时会使用session丢失,对于一些有登录要求的系统将不能获取远程对象
ObjectInputStream objstream = new ObjectInputStream(conn.getInputStream()); User user= (User) objstream.readObject(); return user; }

 

posted on 2017-03-13 10:24  西风古道  阅读(109)  评论(0编辑  收藏  举报