0

I need to make the url be the title of the movie that I return from the database. mywebsite.com/movie_name

The problem is it keeps looping infinitely and never displays my page index.jsp

I know it wouldn't because I need to specify it somewhere but I dont know where. I tried RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("index.jsp/"+movieName) but that doesnt work either it keep looping. plus I don't want my url to have 'index.jsp' int it

public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

    String movieName="movie";
    try {
        movieName = putMovieInSession(request);
    } catch (Exception e) {
        throw new ServletException(e);
    }
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/"+movieName);

    dispatcher.forward(request, response);
}


<servlet>
        <servlet-name>movie</servlet-name>
        <servlet-class>package.MovietServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>movie</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    ...
124697
  • 22,097
  • 68
  • 188
  • 315
  • Try to debug what putMovieInSession does i suspect the control is standing there for some reason. – sumanta Oct 23 '14 at 14:46
  • 1
    Oh yes the servlet is forwarding you to the same page which is creating the infinite loop. Do not forward to the same page. You can print the output in the servlet or redirect to some jsp page. – sumanta Oct 23 '14 at 14:52

3 Answers3

0

If you want to change the url in the browser, you have to perform a redirect.

See also the difference between forward and redirect.

Community
  • 1
  • 1
Christophe Weis
  • 2,518
  • 4
  • 28
  • 32
0

Check the below line, u have to append in correct manner.

RequestDispatcher dispatcher = request.getServletContext().getRequestDispatcher("index.jsp?movieName="+movieName);

and in index.jsp get the movieName from request Object and display where ever u like to show up.Hope this helps..

user4103233
  • 47
  • 1
  • 1
  • 9
0

"/" is your container root which is your catalina home directory not your webapp directory. Try changing it to the following:

RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(movieName);

or

RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(request.getContextPath()+movieName);
Sas
  • 2,473
  • 6
  • 30
  • 47