[英]How to get Session id after validating a user in Restful service?
我正在使用Restful Web Service。我尝试创建会话ID(根据您的示例)。您的示例运行正常。我所做的更改很少(1.向该方法添加了参数 , 在验证用户身份后创建了会话ID,我的方法类型是POST )
它对我的抛出错误(该方法向我返回空值)
这就是我的方法的样子
public String SessionId(
@Context HttpServletRequest req,
@PathParam("username") String username,
@PathParam("passwd") String passwd)
我给了现有的用户名和密码。但是仍然抛出错误。
请告诉我,我做错了什么。
在此先感谢Sudha。
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();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.