I have a web application where the front end is developed via vue-cli and running on localhost:8081 and the back-end is a separated project using tomcat and is running on localhost:8080
the back-end has a controller servlet which, based on an action, the controller delegate the work to another servlet. when the login page submits the login info to the controller, the controller creates the HttpSession, call the LoginServlet which validate the credentials then send the response to the controller which will respond to the login page. Until now if we check the HttpSession on the ControllerServlet and on the LoginServlet they match perfectly.
Now that the login has been successfully vue-router push us the admin component on the url: localhost:8081/admin, at this point we have two get request, both to the ControllerServlet which will delegate the work to another servlet. If we check the session on the controller and this third servlet, they match. BUT if we check the HttpSession from these 3 requests, they all differ from eachother the servlet creates a new one for each of them. How can I make this HttpSession persistent? Is the problem due to the fact that vue is running on 8081 and the back-end is on 8080?
Until now if we check the HttpSession on the ControllerServlet and on the LoginServlet they match perfectly.
Of course, they will match because the session for both ControllerServlet
and LoginServlet
has been created by the same server (which is running at the port, 8080).
The session created by the server running at the port, 8080 has no relation with the server running at the port, 8081 and therefore expecting them to match is wrong. In the rarest of rare occasions, if they match, it can be just a coincidence.
The only way the server running at the port, 8081 can get the session created by the server running at the port, 8080 is through persisting and querying the session i.e. you will have to persist the session created by the server running at the port, 8080 to a data-store (DB, NFS etc.) from where the server running at the port, 8081 will have to query and get it.