John Rumpel
John Rumpel

Reputation: 4615

RequestDispatcher: Servlet mapping doesn't work properly

Its so confusing. Don't have any kind of idea what happend here:

I want to deploy a simple WAR-project. Two HttpServlets, one just forwards the request to another one:

...
String[] selectedOptionsLabels = ...
req.setAttribute("checkedLabels", selectedOptionsLabels);
try {
   req.getRequestDispatcher("/confirmationservlet.do").forward(req, resp);
}
...

When I try to set some values on the form it works great without dispatcher, but when I try this example, my browser can't handle the servlet. It tries to download the file confirmationservlet.do. Confusing.

There seems to be a mapping problem, but I can't figure it out, since the deployment does also work fine.

Do you have an idea?

This is my web.xml (without outer web-app-tag) <--- Only for testing purposes, knowing there are annotations.

<servlet>
    <servlet-name>FormHandlerServlet</servlet-name>
    <servlet-class>
      de.lancom.formhandling.FormHandlerServlet
    </servlet-class>    
</servlet>

<servlet-mapping>
    <servlet-name>FormHandlerServlet</servlet-name>
    <url-pattern>/formhandlerservlet.do</url-pattern>
</servlet-mapping>

<servlet>
    <servlet-name>ConfirmationServlet</servlet-name>
    <servlet-class>
      de.lancom.formhandling.ConfirmationServlet
    </servlet-class>    
</servlet>

<servlet-mapping>
    <servlet-name>ConfirmationServlet</servlet-name>
    <url-pattern>/confirmationservlet.do</url-pattern>
</servlet-mapping> 

<welcome-file-list>
  <welcome-file>dataentry.html</welcome-file>
</welcome-file-list>

Upvotes: 0

Views: 680

Answers (1)

user_CC
user_CC

Reputation: 4776

Try the following method:

    HttpServletResponse#sendRedirect()

to send a redirect.

     response.sendRedirect("/confirmationservlet.do");

Upvotes: 1

Related Questions