In the course of today's project, with JUnit testing, I want to get user on the page end and store user-related information in session, but
Servletactioncontext.getrequest (). GetSession (); Get session, always report null pointer exception, do not know where to go wrong, because this servletactioncontext is not our own write, generally will not have problems, but I do not know where wrong, has been looking for other methods, or no use, the type of other methods are null pointers
Servletactioncontext.getservletcontext ();
Servletactioncontext.getrequest ();
Servletactioncontext.getresponse ();
Then looked up the internet, some people suggested that the method to get the session
Actioncontext Ctx=actioncontext.getcontext ();
Map session = Ctx.getsession ();
But testing with JUnit found that it was still a null-pointer exception.
I later deployed the project to Tomcat, and then started the browser to access, unexpectedly, I do not know what the reason, I guess these session,request,application in the browser will have the effect
Want to know what the reason can tell me, thank you first.