Login user via Servlet
I am trying to login users via a Servlet apposed to using a form with j_security_check.
After a user fills in a registration form, I'm creating the user and also want to log them in.
The below code does create a login token under the users profile however it doesn't change the current login-token cookie.
Is it possible?
byte[] bytes = "j_username=username&j_password=password".getBytes(StandardCharsets.UTF_8); HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:4503/j_security_check").openConnection(); connection.setDoOutput(true); connection.setRequestMethod("POST"); DataOutputStream writer = new DataOutputStream(connection.getOutputStream()); writer.write(bytes);