You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Romain Quilici <r....@chem.usyd.edu.au> on 2006/09/12 07:42:54 UTC

How to redirect to a jsp

Hi all,
this question seems simple, but I did not figure out how to answer it.

In my web.xml I have defined a default servlet. So it can handle 
requests that does not match other servlets pattern.
 <servlet-mapping>
       <servlet-name>DefaultServlet</servlet-name>
       <url-pattern>/</url-pattern>
    </servlet-mapping>

Then in my DefaultServlet, I want to redirect to a jsp page, so I use
RequestDispatcher dispatcher = 
getServletContext().getRequestDispatcher("/jsp/index.jsp");
        if(dispatcher != null){
            dispatcher.forward(request,response);
        }

But doing that, I reenter in my default servlet's doGet method.

What I want is rather simple, when a user connect to the site 
http://server/myapp/, then the request is handled by the default servlet 
and the jsp page is displayed
Thanks for your help
Regards
Romain


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to redirect to a jsp

Posted by Marc Farrow <ma...@gmail.com>.
Tim's solution is the easiest, but allow me to explain why your application
is behaving that way.

By specifying the following

>       <url-pattern>/</url-pattern>
>
>
You are saying that all requests that come into your application are to be
forwarded to the servlet.  Thus when you redirect to "/jsp/index.jsp" it is
taking back into the servlet.  My guess is that you are trying to force
everyone to the /jsp/index.jsp" page no matter which "url" they use to get
to your application.  I do not know of an easy way to do this.  I like Tim's
solution and hopefully that will fulfill your needs.

HTH


On 9/12/06, Tim Funk <fu...@joedog.org> wrote:
>
> If I am reading this correctly, an "easier" solution would be to create
> an index.jsp at the root level that forwards to "/jsp/index.jsp"
>
> -Tim
>
> Romain Quilici wrote:
> > Hi all,
> > this question seems simple, but I did not figure out how to answer it.
> >
> > In my web.xml I have defined a default servlet. So it can handle
> > requests that does not match other servlets pattern.
> > <servlet-mapping>
> >       <servlet-name>DefaultServlet</servlet-name>
> >       <url-pattern>/</url-pattern>
> >    </servlet-mapping>
> >
> > Then in my DefaultServlet, I want to redirect to a jsp page, so I use
> > RequestDispatcher dispatcher =
> > getServletContext().getRequestDispatcher("/jsp/index.jsp");
> >        if(dispatcher != null){
> >            dispatcher.forward(request,response);
> >        }
> >
> > But doing that, I reenter in my default servlet's doGet method.
> >
> > What I want is rather simple, when a user connect to the site
> > http://server/myapp/, then the request is handled by the default
> > servlet and the jsp page is displayed
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


-- 
Marc Farrow

Re: How to redirect to a jsp

Posted by Tim Funk <fu...@joedog.org>.
If I am reading this correctly, an "easier" solution would be to create 
an index.jsp at the root level that forwards to "/jsp/index.jsp"

-Tim

Romain Quilici wrote:
> Hi all,
> this question seems simple, but I did not figure out how to answer it.
>
> In my web.xml I have defined a default servlet. So it can handle 
> requests that does not match other servlets pattern.
> <servlet-mapping>
>       <servlet-name>DefaultServlet</servlet-name>
>       <url-pattern>/</url-pattern>
>    </servlet-mapping>
>
> Then in my DefaultServlet, I want to redirect to a jsp page, so I use
> RequestDispatcher dispatcher = 
> getServletContext().getRequestDispatcher("/jsp/index.jsp");
>        if(dispatcher != null){
>            dispatcher.forward(request,response);
>        }
>
> But doing that, I reenter in my default servlet's doGet method.
>
> What I want is rather simple, when a user connect to the site 
> http://server/myapp/, then the request is handled by the default 
> servlet and the jsp page is displayed 
 

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to redirect to a jsp

Posted by Bill Barker <wb...@wilshire.com>.
"Romain Quilici" <r....@chem.usyd.edu.au> wrote in message 
news:450648DE.6030003@chem.usyd.edu.au...
> Hi all,
> this question seems simple, but I did not figure out how to answer it.
>
> In my web.xml I have defined a default servlet. So it can handle requests 
> that does not match other servlets pattern.
> <servlet-mapping>
>       <servlet-name>DefaultServlet</servlet-name>
>       <url-pattern>/</url-pattern>
>    </servlet-mapping>
>
> Then in my DefaultServlet, I want to redirect to a jsp page, so I use
> RequestDispatcher dispatcher = 
> getServletContext().getRequestDispatcher("/jsp/index.jsp");
>        if(dispatcher != null){
>            dispatcher.forward(request,response);
>        }
>
> But doing that, I reenter in my default servlet's doGet method.
>

Unless you explicitly map them otherwise, things like stylesheets and images 
will typically get mapped to your DefaultServlet.

> What I want is rather simple, when a user connect to the site 
> http://server/myapp/, then the request is handled by the default servlet 
> and the jsp page is displayed
> Thanks for your help
> Regards
> Romain
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
> 




---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org