I am using jersey-js-rs in myeclipse as the backend of my project and jsp as an interface. I want to set a cookie from the server after a successful login. In a Jersey whitepaper, I can only find how to get cookies from knitwear. Can anyone give me a demo to do such things?
This is my part of the login, and I am returning the response and redirecting the URL "/", which means index.jsp.
@Path("/login") @POST @Consumes("application/x-www-form-urlencoded") public Response login(@FormParam("email") String email, @FormParam("password") String password) { Map<String, Object> model = MapFactory.newHashMapInstance(); model.put("email", email); model.put("password", password); loginCheck(model); if (model.get("emailCheck").equals("ok") && model.get("passwordCheck").equals("ok")) { return Response.ok( new Viewable("/index", new NewCookie("name", "Hello, world!"))).build(); } else { return Response.ok(new Viewable("/login", model)).build(); } }
This is my "/" part:
@GET @Produces("text/html") public Response getIndex(@CookieParam("name") String name) { HashMap<String, Object> model = MapFactory.newHashMapInstance(); model.put("name", name); System.out.println("cookie name:\t" + name); return Response.ok(new Viewable("/index", model)).build(); }
Every time I run this code, I find that I cannot get a cookie from part of the index. If you also ever bothered with this question and finally resolved it, plz give me some directions, thanks.
jsp cookies jersey
mons
source share