|
程序如下,最后的sendRedirect("../../x5/UI2/waimai/indextest.w") ,这个页面在开发工具本地已经可以正常浏览访问,但这个sendRedirect 好像没有什么用,该怎么实现服务器端的页面跳转呢?
只能在客户端写 window.location.href="./indextest.w" 这样来实现吗?
private static void ChkLogin(ServletRequest request, ServletResponse response) throws SQLException, IOException, NamingException {
HttpServletRequest hrqst = (HttpServletRequest)request;
JSONObject params = (JSONObject) JSONObject.parse(request.getParameter("params"));
String customIDInput = params.getString("CustomerID"); //前端传入的用户ID
String id ; // SESSION中的用户ID
PrintWriter out = response.getWriter();
// 获得session
HttpSession session = hrqst.getSession(false);
if(session!=null)
{
id = (String)session.getAttribute("CustomerID");
System.out.println("获得的Session id : " + session.getId().toString() + " Session CustomerID : " + id );
System.out.println();
if (customIDInput != id)
{
System.out.println("never login id not correct");
HttpServletResponse rsHttp = (HttpServletResponse)response;
//没有登录过,跳转到登录画面
rsHttp.sendRedirect("../../x5/UI2/waimai/indextest.w");
}
}
else
{
System.out.println("never login ");
HttpServletResponse rsHttp = (HttpServletResponse)response;
//没有登录过,跳转到登录画面
rsHttp.sendRedirect("../../x5/UI2/waimai/indextest.w");
}
} |
|