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)
//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)
就是String[]类型的
main方法取不到session???
是这样吗