1

I'm running tomcat 6 and using jsp , trying to have a login page on my site which uses tomcat BASIC , I followed this and other tutorials http://www.jguru.com/faq/view.jsp?EID=239670 but still no luck ....Would anyone be able to tell me explicitly what to do? I Know form based is better but I have to use basic, thanks

The status 500 error being thrown is as follows

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

    javax.servlet.ServletException: 

    java.lang.NoClassDefFoundError:org/apache/jasper/compiler/ErrorDispatcher
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:268)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

    java.lang.NoClassDefFoundError: org/apache/jasper/compiler/ErrorDispatcher
org.apache.jasper.compiler.Compiler.compile(Compiler.java:350)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:321)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.35 logs.

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
H65
  • 51
  • 1
  • 8
  • Read this tutorial which has both explanations and examples: [Declarative Web Application Security](http://courses.coreservlets.com/Course-Materials/pdf/msajsp/03-Security-Declarative.pdf). From page 35 it explains *BASIC authentication* and gives a step by step example of how to setup BASIC authentication. This tutorial is from the popular series of tutorials: [Advanced Servlet and JSP Tutorials](http://courses.coreservlets.com/Course-Materials/msajsp.html) – informatik01 Apr 04 '13 at 18:21
  • And of course there is also an official [Java EE 6 Tutorial](http://docs.oracle.com/javaee/6/tutorial/doc/gijrp.html) which might be of a help. – informatik01 Apr 04 '13 at 18:30
  • Tried both BASIC and form because I couldnt get basic to work , still no joy :( – H65 Apr 04 '13 at 20:08
  • It's strange, because both BASIC and FORM security are quite easy to configure. It's hard to say what you are doing wrong without seeing. Try this tutorial, maybe it will help you: [How do I use Basic authentication with Tomcat?](http://www.avajava.com/tutorials/lessons/how-do-i-use-basic-authentication-with-tomcat.html) – informatik01 Apr 04 '13 at 20:20
  • Thanks I'll try this , I'm now encountering a problem with the speed of tomcat , It's slowed right down when trying to view .jsp , I've removed all breakpoints as several threads suggested but still no luck – H65 Apr 05 '13 at 16:00
  • You can also try this: [Beginning & Intermediate Servlet & JSP Tutorials](http://courses.coreservlets.com/Course-Materials/csajsp2.html). Aside from the nice explanations, this tutorials has not only the ready to use source code for you to download in zip archive, but also preconfigured Tomcat instance (see "*Servlets & JSP: Overview and Setup*"), that you can also download. So you can't go wrong with this. – informatik01 Apr 05 '13 at 16:20
  • btw The first tutorials [Advanced Servlet and JSP Tutorials](http://courses.coreservlets.com/Course-Materials/msajsp.html) are the sequel to [Beginning & Intermediate Servlet & JSP Tutorials](http://courses.coreservlets.com/Course-Materials/csajsp2.html). So there have also ready to download source code etc – informatik01 Apr 05 '13 at 16:32

1 Answers1

0

In your web.xml you need at least:

   <security-role><role-name>member</role-name></security-role>
   <security-role><role-name>admin</role-name></security-role>

   <login-config>
    <auth-method>BASIC</auth-method>
   </login-config>

   <security-constraint>
    <web-resource-collection>
        <web-resource-name>For Members and Admin Only</web-resource-name>
        <description>This Description is Optional</description>
        <url-pattern>/Examples/protected/*</url-pattern>
    </web-resource-collection>

    <auth-constraint>
        <role-name>admin</role-name>
        <role-name>member</role-name>
    </auth-constraint>

   </security-constraint>

In your tomcat-users.xml you need something like:

  <role rolename="member"/>
  <role rolename="admin"/>
  <user username="ricky" password="rrrrr" roles="admin,member"/>
Richard Wеrеzaк
  • 1,551
  • 1
  • 13
  • 17
  • Yip I have all that added in , However when I log on it is throwing a status 500 error : – H65 Apr 05 '13 at 14:02
  • I'm wondering if this is the problem , in my web.xml I have /intro/* .....The address of the first page is http://localhost:8080/intro/Question_1.jsp .... is this the error maybe ? – H65 Apr 05 '13 at 14:30
  • @Heafy65 In your case, `intro` is your web application "context root". DON'T write in inside `` when specifying mappings. The **forward slash** represents "root context". So just put `/*`. Also see this answer about mapping requests to servlets: http://stackoverflow.com/a/14225540/814702 – informatik01 Apr 05 '13 at 16:13