package com.logic.mail;import uk.ltd.getahead.dwr.*;/*** DWR的session操作类* @author sunylat*/public class DwrSession {    //得到session编号    public String getSessionId() {        WebContext webContext = WebContextFactory.get();        webContext.getSession();        webContext.getHttpServletRequest();        webContext.getHttpServletResponse();        return webContext.getSession().getId();    }        /**     * 设定制定的session值     * @param value 要设定的session值     * @param sessionName session名称     */    public void setSession(String sessionName,String value){       WebContext webContext = WebContextFactory.get();          //设定session值          webContext.getSession().setAttribute(sessionName,value);    }        /**     * 获取指定的session值     * @param sessionName session名称     * @return     */    public String[] getSession(String sessionName){        WebContext webContext = WebContextFactory.get();            //返回session值
        //session.setAttribute("result", result);
        return (String[])webContext.getSession().getAttribute("result");    }
    public static void main(String args[]){
     DwrSession ds = new DwrSession();
    
//        String[] result1 = new String[2];
//        result1[0] = "dddd";
//        result1[1] = "1";
//        for(int i=0;i<result1.length;i++){
//         System.out.println(result1[i]);
//        }
     String result2 = "ddd";
     String  result1 = "1";
     ds.setSession("result1",result1);
     ds.setSession("result2",result2);
     String m = ds.getSession("result1").toString();
     String n = ds.getSession("result2").toString();
     System.out.println(m);
     System.out.println(n);
    }}Exception in thread "main" java.lang.NullPointerException
at uk.ltd.getahead.dwr.WebContextFactory$ProxyWebContext.getSession(WebContextFactory.java:150)
at com.logic.mail.DwrSession.setSession(DwrSession.java:53)
at com.logic.mail.DwrSession.main(DwrSession.java:89)

解决方案 »

  1.   

    还有啊,请问session里面可以存数组吗
    就是String[]类型的
      

  2.   

    session里面什么都可以存啊,只不过一般的不存session里面的,request是你存储信息不错的选择
      

  3.   

    请问楼上的朋友
    main方法取不到session???
    是这样吗
      

  4.   

    楼主的问题有解决吗?我也碰到这样的问题WebContext ctx = uk.ltd.getahead.dwr.WebContextFactory.get();获取的就是NULL