Dear folks:

  I hava almonst same question.
  I am using jsp1.0 (maybe same as JSDK 2.1).
  I want to restrict to accesss some directory.

        http://localhost:8080/restricted
        (C:\jsp1.0\webpages\restricted)

  These are setting files,

C:\jsp1.0\webpages\WEB-INF\mapping.properties:
        /restricted=restrict

C:\jsp1.0\webpages\WEB-INF\servlets.properties:
        restrict.code=Restrict

and Restrict servlet is
C:\jsp1.0\webpages\WEB-INF\servlets\Restrict.class.

  If a client accesses

        http://localhost:8080/restricted/index.html

Restrict first checks session object, and if it does not exist,
redirects to Login servlet. If it exists, index.html is served by
builtin FileServlet.

  Restrict servlet below shows not /restricted/index.html but
/index.html, because s = "/index.html".

----------------------------------------------------------------------
public class Restrict extends HttpServlet
{
    public void service(HttpServletRequest req, HttpServletResponse res)
        throws IOException
    {
        // if session object exists
        String s = req.getPathInfo();
        RequestDispatcher rd = getServletContext().getRequestDispatcher(s);
        try {
            rd.forward(req, res);
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }
}
----------------------------------------------------------------------

  If I change to

        String s = "/restricted"+req.getPathInfo();

it makes infinite loop. How should I do?

        Ryo Iwasaki, NTT
        [EMAIL PROTECTED]

JPL <[EMAIL PROTECTED]> wrote:

> Hello,
>
> I downloaded JSDK 2.1a from java.sun.com recently and I am using
> the web server included in this package (once known as "servletrunner")
> to experiment with servlets.
>
> What I would like to do is that one servlet, which controls granting
> access based on user/pass, lets another one display the welcome
> page after successful login. The page displayer can be accessed
> as follows from the browser:
>
> http://localhost:8080/jpl/servlet/passgate/somepage.html
>
> (passgate is the servlet's name)
>
> However, when I try to forward a request from the other servlet
> to it, like below:
>
>   RequestDispatcher rd =
>    getServletConfig().getServletContext().getRequestDispatcher (
>     "/jpl/servlet/passgate/secret.html");
>
>   rd.forward (req, res);
>
> I get an error:
> "The page you are looking for cannot be displayed because
> the address is incorrect. HTTP 405 - Resource not allowed"
>
> The documentation of RequestDispatcher does not give me a clue
> of what can be wrong - I suspect that the web server from JSDK
> works wrongly. Because I am newbie to servlets though, the reason
> can as well be my lack of understanding.
>
> Also, the following piece of documentation (about
> RequestDispatcher.forward) is unclear to me:
>
> "You cannot use forward if the target resource has already returned
> a ServletOutputStream or PrintWriter object to the servlet. In that
> situation,
> forward throws an IllegalStateException."
>
> "the target resource has already returned..." -
> how can it "return" a PrintWriter? return it to where?
>
> Thanks for your help in advance -
> JPL
>
> http://www.kki.net.pl/jpl
> Remote Java Development
>
> --
> Wyslano przez bezplatny serwer KKI

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to