My site goes to a login page that I want to redirect to another page when the user logs in. I have a "POST" method that sends the "username" and "password" to the server and the server checks if the username and password exist.
Here is my method
@POST
@Path("logIn")
public void signIn(@PathParam("profileName") String profileName, @PathParam("password") String password) {
if (profileService.getProfile(profileName) != null && (profileService.getPassword(profileName)).equals(password)){
//Render a new page ex "feed.jsp"
}
else {
//send unsucessful message back to client??
}
The Client is able to POST the username and password properly and check if it exists... I just have no idea how to make it render (redirect to???) a new page
You could...
Redirect, (using
Response.seeOther(URI)
, passing any needed values as query parameters. For exampleNote: please see correction to this option in this answer. The above will not work.
Or you could..
Use Jersey's JSP MVC feature, and also clearly demonstrated here. For example
feed.jsp
Aside: Do you really want to pass the password in the URI path? hat's a huge security risk. Better actually pass it in the body of the request.
UPDATE
Now that I think about it, you should always redirect from the login POST, per the POST/REDIRECT/GET pattern. If you want to use the JSP MVC for the entire approach, you can have a controller returning a
Viewable
for the login page (on GET), and on success (POST), redirect to the feed controller, else redirect back the same login page (GET). There a are few different solutions.For example