0

I am working on Restful web Service.I tried to create session id(from your example).Your example is working fine.I have just made few changes(1.Added Parameter to the method,created the session id after validating the user and my method type is POST)

Its throwing error for me(that method returning me a null value)

This is how my method will look like

 public String SessionId(
     @Context HttpServletRequest req,
     @PathParam("username") String username,
     @PathParam("passwd") String passwd)

I gave existing username and password.but still its throwing an error.

please tell me,where i have done wrong.

Thanks in Advance, Sudha.

Eric Stein
  • 13,209
  • 3
  • 37
  • 52
Sudha Velan
  • 633
  • 8
  • 24
  • 1
    Please use code tags. Whose example? What is the body of the method? Nobody will be able to help you without more information. – Eric Stein Sep 16 '13 at 11:46
  • This is the example i refered [rest example program](http://stackoverflow.com/questions/909185/jersey-security-and-session-management).I got session id, i tried in new package and the error is resolved. Thank you for the reply. – Sudha Velan Sep 17 '13 at 05:21
  • @SudhaVelan Please don't add contextless tag-links into post-bodies. These don't add any value beyond the tags in the tag-section. – piet.t Jul 11 '17 at 11:40

1 Answers1

0

https://stackoverflow.com/a/25885938/1561948

   @Path("/helloworld")
public class HelloWorld {
        @GET
    @Produces("text/plain")
    public String validateuser(@Context HttpServletRequest req) {

        HttpSession session= req.getSession(true);
        Object foo = session.getAttribute("uid");
        if (foo!=null) {
            System.out.println(foo.toString());
        } else {
            foo = "bar";
            session.setAttribute("uid", "bar");
        }
        return foo.toString();

    }
}
Community
  • 1
  • 1
ThmHarsh
  • 601
  • 7
  • 7