How one servlet to transfer a request to another servlet. If the servlets are in the same package as the url.
1 answer
If I understand your question correctly, you can call request.getRequestDispatcher("<урл второго сервлета>").forward(request, response); from the first servlet request.getRequestDispatcher("<урл второго сервлета>").forward(request, response);
- If the servlets are in the same package, what will the path look like? - Yevgeny Efimenko
- There it’s important not in what package are servlets, but mapping on them is carapuz
- Please clarify what mapping means - Evgeny Efimenko
- Mapping is an indication of the address at which the servlet will be available. It is specified either in web.xml or using annotations. See an example: mkyong.com/servlet/a-simple-servlet-example-write-deploy-run - carapuz
- There is another function:
request.getServletContext().getNamedDispatcher(servletName).forward(...)name of the servlet is used. The name is assigned in web.xml. Andrequest.getServletContext().getRequestDispatcher(...)slightly different from the one already proposed byrequest.getRequestDispatcher(...)- Sergey
|