Servlet:
@WebServlet("/") public class MainServlet extends HttpServlet { double counter = 0; @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setAttribute("counter", counter); req.setAttribute("name", "VII"); req.getRequestDispatcher("mypage.jsp").forward(req, resp); counter++; } } Jsp page:
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> <h1>Helo, ${name}!</h1> <h3>This page was visited: <strong>${counter}</strong> time</h3> </body> </html> Why counter is increased by 2 instead of 1: Launched via debugger ... doGet is called 2 times when the page is reloaded, but why? Deployl on tomcat (full code: github )
req.getRequestURL()- default locale