【发布时间】:2015-05-12 16:24:52
【问题描述】:
我是 Jersey REST 框架的新手,如果这是一个愚蠢的问题,请原谅。
我将 Tomcat 与 Hibernate 和 Jersey REST Web 服务一起使用。
我的 Web APP 中有一组 HTML 页面
login.html
dealer.html
sales.html
我不希望用户直接访问除 login.html 之外的 HTML 页面
所以要解决这个问题,当按下提交时,在 login.html 下调用
对后端进行以下调用
@Path("/webchecklogin")
public class WebLoginCheck {
@Context
private HttpServletResponse response;
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces("application/json")
public String getData(LoginInfo loginInfo ) throws JSONException,ClassNotFoundException, SQLException
{
String ID = loginInfo.getID();
String email = loginInfo.getEmail();
// validate this values with Database and if successfully logged in , stored them in session AND cookies also
}
}
在dealer.html 和sales.html 中,在页面准备就绪时,我正在调用如下所示的服务
var checkcallajax = $.ajax({
type: 'GET',
url: url + '/ORIENT/orn/checkifuserloggedin',
jsonpCallback: 'jsonCallback',
success: function(response) {
}
})
@Path("/checkifuserloggedin")
public class CheckIfUserLoggedIn {
@Context
private HttpServletRequest request;
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces("application/json")
public String checkIfUserLoggedIn() throws JSONException,ClassNotFoundException, SQLException
{
// On what basis , should i check wheher the USER is logged or NOT
// I tried storing data with Session and cookies , but i am unable to retrive them here
//return true or false
// based on true or false , i am redireting user to appropiate page
}
}
谁能告诉我如何处理这个问题
【问题讨论】: