security-constraint on servlet-mapping

Discussion in 'Java' started by harryos, Nov 25, 2008.

  1. harryos

    harryos Guest

    hi

    i wanted to prevent users from calling my servlets directly and wrote
    a controller servlet which takes a request parameter and redirects to
    the other servlets by means of a RequestDispatcher
    I put the servlet mappings for the servlets inside a <security-
    constraint> block .

    <security-constraint>
    <servlet-mapping>
    <servlet-name>Weather</servlet-name>
    <url-pattern>/weather</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>Maps</servlet-name>
    <url-pattern>/maps</url-pattern>
    </servlet-mapping>
    </security-constraint>

    and the controller servlet is invoked by any url
    <servlet-mapping>
    <servlet-name>ControllerServlet</servlet-name>
    <url-pattern>/*</url-pattern>
    </servlet-mapping>

    In the Controller i used

    RequestDispatcher dispatcher = null;
    String param = request.getParameter("go");
    if (param == null)
    throw new ServletException("Missing parameter in Controller.");
    else if (param.equals("weather"))
    dispatcher = request.getRequestDispatcher("/weather");
    else if (param.equals("maps"))
    dispatcher = request.getRequestDispatcher("/maps");
    if (dispatcher != null)
    dispatcher.forward(request,response);

    When i call http://localhost:8080/myapp/?go=weather it causes
    java.lang.StackOverflowError..

    The program works if i don't use the
    <security-constraint> </security-constraint> block around the mapping
    for the two servlets.But then anyone can call them by
    http://localhost:8080/myapp/weather or http://localhost:8080/myapp/maps
    ...
    can someone explain why i am getting this error?
    harryos, Nov 25, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Albretch
    Replies:
    2
    Views:
    937
    William Brogden
    Jul 11, 2003
  2. Justin
    Replies:
    1
    Views:
    3,086
    Scott Yanoff
    Aug 11, 2003
  3. bootman
    Replies:
    0
    Views:
    564
    bootman
    Aug 11, 2003
  4. circuit_breaker
    Replies:
    2
    Views:
    1,995
    Jack Jia
    Apr 4, 2004
  5. puvit82
    Replies:
    4
    Views:
    760
    puvit82
    Feb 1, 2008
Loading...

Share This Page