If I have two servlets:
@WebServlet (urlPatterns = {"/s1"})
public class Servlet1 extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("A", 100);
map.put("B", 200);
map.put("C", 300);
req.setAttribute("map", map);
getServletContext().getRequestDispatcher("Servlet2").forward(req, resp);
}
}
public class Servlet2 extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
Map map = (Map) req.getAttribute("map");
for (Object o : map.values()) {
System.out.println(o);
}
}
}
How can I make redirect between them? And which path I need to use in my getRequestDispatcher method? And one more condition - Servlet2 must be without any mapping in annotations or in web.xml.