You could...
Redirect, (using Response.seeOther(URI)
, passing any needed values as query parameters. For example
@POST
@Path("logIn")
public Response login(@Context ServletContext context) {
UriBuilder uriBuilder = UriBuilder.fromUri(URI.create(context.getContextPath()));
uriBuilder.path(.. <path-to-your-jsp> ..);
uriBuilder.queryParam("key1", "value1");
uriBuilder.queryParam("key1", "value2");
URI uri = uriBuilder.build();
return Response.seeOther(uri).build();
}
Note: 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
@POST
@Path("logIn")
public Viewable login() {
Map<String, String> model = new HashMap<>();
model.put("key1", "value1");
model.put("key2", "value2");
return new Viewable("/feed", model);
}
feed.jsp
<html>
<body>
<p>${it.key1}</p>
<p>${it.key2}</p>
</body>
</html>
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
@Path("/login")
public class LoginController {
@GET
public Viewable loginPage() {
...
return new Viewable("/login", model); // to login.jsp
}
@POST
public Response loginPost(Form form, @Context UriInfo uriInfo) {
...
UriBuilder builder = uriInfo.getBaseUriBuilder();
if (success) {
builder.path("/feed"); // to FeedController GET
} else {
builder.path("/login"); // to LoginController GET
}
return Response.seeOther(builder.build()).build();
}
}
@Path("/feed")
public class FeedController {
@GET
public Viewable getFeed() {
...
return new Viewable("/feed", model); // to feed.jsp
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…