Obviously, if you don't have a session,
ses.get("context") will return null.
And null.toString() that's a nice NPE.
I usually use StringUtils.isNotEmpty for commons-lang :
http://commons.apache.org/lang/api-release/org/apache/commons/lang/StringUtils.html#isNotEmpty(java.lang.String) <http://commons.apache.org/lang/api-release/org/apache/commons/lang/StringUtils.html#isNotEmpty%28java.lang.String%29>
Denis.
Nguyen Xuan Son a écrit :
dear all
I have the C0002_Home.jsp and sessionChk.jsp files. The C0002_Home.jsp's
source code is
<s:action name="SessionCheck"></s:action>
the meaning of this source code is to check users session whenever they
enter the webpage
the struts.xml is structured as:
<action name="SessionCheck" class="com.baibai.action.SessionCheckAction">
<result name="input">sessionChk.jsp</result>
</action>
<action name="C0002_Home" class="com.baibai.action.C0002_HomeAction">
<result name="input">C0002_Home.jsp</result>
</action>
the detail of the SessionCheckAction.java file is
public class SessionCheckAction extends ActionSupport{
public String execute() throws Exception {
Map ses = ActionContext.getContext().getSession();
if((ses.get("context").toString()!="")&&(ses.get("role").toString()=="admin")){
// the user is loginned as an administrator
System.out.println("you have session");
} else {
System.out.println("you dont have session");
}
return SUCCESS;
}
}
however when i tried to enter the C0002_Home.jsp without Login
the error appears
2009/11/30 10:40:07
com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
致命的: Could not execute action: /SessionCheck
java.lang.NullPointerException
at com.baibai.action.SessionCheckAction.execute(SessionCheckAction.java:10)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
this doesnt happen if I login into the system
could you tell me where did I went wrong
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org