java.lang.ClassCastException: java.lang.String cannot be cast to common.User
java.lang.ClassCastException: java.lang.String cannot be cast to common.User
at Server.RequestProcessor.logout(RequestProcessor.java:147)
at Server.RequestProcessor.run(RequestProcessor.java:38)
at java.lang.Thread.run(Thread.java:662)
其中User是
public class User implements Serializable {
private static final long serialVersionUID = -427838794924380991L;
private String id;
private String password;
private String box1;
private String grade;
private String department;
private String ip;
public User(String id,String password, String box1, String department,String grade,String ip) {
this.id=id;
this.password = password;
this.box1 = box1;
this.department =department;
this.grade = grade;
this.ip = ip;
}
public User(String id, String password) {
this.id = id;
this.password = password;
}
报错的地方是:
/** 客户端退出 */
public boolean logout(OnlineClientIOCache oio, Request request) throws IOException{
System.out.println(currentClientSocket.getInetAddress().getHostAddress()+ ":" + currentClientSocket.getPort() + "走了");
User user0 = (User)request.getAttribute("user");
ServerDataBuffer.onlineUserIOCacheMap.remove(user0.getid());//把当前上线客户端的IO从Map中删除
ServerDataBuffer.onlineUsersMap.remove(user0.getid());//从在线用户缓存Map中删除当前用户
Response response = new Response(); //创建一个响应对象
response.setType(ResponseType.LOGOUT);
response.setData("logoutUser", user0);
oio.getOos().writeObject(response); //把响应对象往客户端写
oio.getOos().flush();
currentClientSocket.close(); //关闭这个客户端Socket
ServerDataBuffer.onlineUserTableModel.remove(String.valueOf(user0.getid())); //把当前下线用户从在线用户表Model中删除
return false; //断开监听
}
这是什么原因啊?
[解决办法]