Reputation: 345
I have a login servlet that processes post request with username and password parameters, and does something like this:
Instant pageGenStart = Instant.now();
String username = req.getParameter("username");
String password = req.getParameter("password");
resp.setContentType("text/html;charset=utf-8");
User user = null;
try {
user = userService.getByUsername(username);
} catch (SQLException e) {
e.printStackTrace();
}
if (user == null && !password.equals("")) {
try {
user = new User(username, password);
user.setId(userService.addNewUser(username, password));
charactersService.addNewCharacter(user);
sessionsService.add(req.getSession().getId(), user.getId());
} catch (SQLException e) {
e.printStackTrace();
}
resp.setContentType("text/html;charset=utf-8");
resp.setStatus(HttpServletResponse.SC_OK);
Duration time = Duration.between(pageGenStart, Instant.now());
resp.sendRedirect("/main");
}
If user is not found in db, create new user and redirect him to main page. Normally i would just put this "time" variable into page, but i redirect my response to other servlet where doGet method is called. How do i let other servlet know how long login servlet took to proccess post request?
Upvotes: 0
Views: 50
Reputation: 481
You can pass value from one servlet to another in many ways like :
I perfer EH-cache for these kind of perposes you can see a good example from the Link.
Upvotes: 1