Hello. Trying to make Servlet redirect request to JSP. I use RequestDispatcher.

Here is the servlet code:

public class ServletDispatcher extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp"); dispatcher.forward(request,response); } } 

Web.xml:

 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <servlet> <servlet-name>ServletDispatcher</servlet-name> <servlet-class>com.geraltsx.library.web.controlers.ServletDispatcher</servlet-class> </servlet> <servlet-mapping> <servlet-name>ServletDispatcher</servlet-name> <url-pattern>/servlet</url-pattern> </servlet-mapping> </web-app> 

index.jsp is located in the web folder of the project, next to WEB-INF:

 <%@page contentType="text/html" pageEncoding="UTF-8" %> <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Документ</title> </head> <body> <h1>пРивет</h1> </body> </html> 

I use the server GlassFish. When entering the browser url http: // localhost: 8080 / app / servlet gives 404 error ((

Closed due to the fact that the participants are off topic: Sergey Gornostaev , aleksandr barakin , ߊߚߤߘ , αλεχολυτ , MihailPw Jun 14 '17 at 6:23 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Sergey Gornostaev, aleksandr barakin, ߊߚߤߘ, αλεχολυτ, MihailPw
If the question can be reformulated according to the rules set out in the certificate , edit it .

    2 answers 2

    Try request.getRequestDispatcher("index.jsp") or request.getRequestDispatcher("/app/index.jsp") .

      The problem was in the wrong project delay. The code itself is working