我们在做JSP页面的时候有时会把某个对象放到request当中,比如
有一个Student对象放在request中
Student s=new Student();
request.setAttribute("stu",s);然后我们在另一个页面把它取出来
Student ss=(Student)request.getAttribute("stu");这时要用到强制转换(Student),但我想动态的获取它,
我知道要获取Student对象可以用:request.getAttribute("stu").getClass();
但这时它还只是个Object,
我用这段话代替(Student)的时候却不行,
(request.getAttribute("stu").getClass())request.getAttribute("stu");请问我要怎么写????????

解决方案 »

  1.   

    你为什么要那样啊..如果实在要那样的话,你可以写一个接口来做啊..把要用的类implements 接口,然后用接口来获取啊!!!!!!!!!!!!!!11
      

  2.   

    我想如何我传的是其它的对象,
    比如说Person一个对象,那个页面也能获得到
      

  3.   

    试试这个
    (request.getAttribute("stu").getClass().getName())request.getAttribute("stu");
      

  4.   

    这样不行的,我试过了,
    request.getAttribute("stu").getClass().getName()
    是个String类型