STRUTS2 action NULL pointer exception Org.apache.struts2.ServletActionContext Java.lang.NullPointerException

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.