Search code examples
servletsauthenticationglassfish-3

HttpServletRequest#login() method not found in eclipse


I'm trying to get this example to work: http://jugojava.blogspot.de/2011/07/jsf-form-authentication-on-servlet-3.html The Problem occures at:

request.login(username, password);

Eclipse says: "The method login() is undefined for the type HttpServletRequest". I'm using jdk 1.7 with Mojarra 2.1.0 and Glassfish 3.1.

Thanks for any help!


Solution

  • That method is introduced since Servlet 3.0. So, it's only available if you configure and develop your project against a Servlet 3.0 compatible container such as Glassfish 3.x.

    However, you seem to already have Glassfish 3.x. Then there are other possible causes for this particular problem, given that you're developing in Eclipse:

    • Glassfish isn't been associated as project's target runtime. In project's properties, make sure it's been selected in Targeted Runtimes section. This way Eclipse will automagically include its libraries in the project's buildpath.

      enter image description here

    • Project isn't been configured as Servlet 3.0 project. In project's properties, make sure Dynamic Web Module version is set to 3.0 in Project Facets section. This way Eclipse will automagically build against version 3.0 instead of a lower one.

      enter image description here

    • You've manually downloaded arbitrary javaee.jar and/or servlet-api.jar files of a completely different servletcontainer version and placed it in project's buildpath/classpath via /WEB-INF/lib which is getting precedence over Glassfish's own libraries. This is utterly wrong. You should not do that. Undo all those changes. This is unnecessary if you properly specify the server as targeted runtime.

    See also: