1

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!

hFonti
  • 187
  • 1
  • 4
  • 11

2 Answers2

1

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thank you for the reply! Glassfish had not been selected as targeted runtime, but it still does no solve the issue. The other settings are exactly as shown in your picture. Do you have any other idea where the mistake could have its origin? – hFonti Apr 18 '13 at 18:08
  • Did you clean and rebuild the project? Did you pay attention to the third point of the answer as to loose JAR files in `/WEB-INF/lib`? If you actually got other Servlet classes/methods to compile while not having a targeted runtime associated, then chances are big that you indeed did that. – BalusC Apr 18 '13 at 18:11
  • Yes I cleaned the project up. The only archive except the Glassfish libs and JRE System Library is the Primefaces-3.5.jar – hFonti Apr 18 '13 at 18:24
  • 1
    The problem suggests that you *still* have an older versioned Servlet API related JAR file somewhere in your buildtime classpath. Check the paths covered by that: `Webapp/WEB-INF/lib`, `JRE/lib`, `JRE/lib/ext` – BalusC Apr 18 '13 at 18:32
  • I Found it! Thank you, you pushed me in the right direction. I had recently added the grizzly-comet-webserver-1.9.46.jar to the glassfish modules, to try out websockets. Turns out it seems to include an older version of the HttpServletRequest Class. – hFonti Apr 18 '13 at 18:46
0

Add Servlet 3.0 API jar to the classpath , or use a Container which supports Servlet 3.0.

AllTooSir
  • 48,828
  • 16
  • 130
  • 164