所以我在landing.jsp
上有这个 <div class="nav-right nav-menu" id="nav-menu">
<a class="nav-item is-hidden-tablet is-active roboto strong letter-space-1" href="toLoginPage.action">HOME</a>
<a class="nav-item is-hidden-tablet roboto strong letter-space-1" href="about.action"/>"> ABOUT </a>
<a class="nav-item is-hidden-tablet roboto strong letter-space-1" href="contact.html"> CONTACT </a>
<a class="nav-item roboto strong letter-space-1" id="login-btn"> LOGIN </a>
</div>
因此,我尝试做的是当我在着陆页(landing.jsp)上时,我希望用户能够通过单击着陆页的导航栏导航到about页面。但一般来说,它不会切换jsp&#39>
这是我的控制器
@RequestMapping(value="toLoginPage")
@ResponseBody
public String toNewLoginPage(HttpServletRequest request, HttpServletResponse response){
Cookie[] cookieArr=request.getCookies();
if(cookieArr==null) {
return "login/landing";
}
for(Cookie cookie:cookieArr){
System.out.println(cookie.getName());
if(cookie.getName().equals("userInfo")){
String userIdStr=cookie.getValue();
long userId=Long.parseLong(userIdStr);
UserBean userBean=userService.getUserById(userId);
HttpSession session=request.getSession();
session.setAttribute(Constant.SESSION_USER, userBean.getId()+"");
if(userBean.getIsActive()==1){
session.setAttribute(Constant.SESSION_IS_ACTIVE, true);
}else{
session.setAttribute(Constant.SESSION_IS_ACTIVE, false);
}
request.setAttribute("MsgModuleUrl", CurisConfig.CurisConfig.MODULE_ADDRESS.MsgModule);
request.setAttribute("formula", CurisConfig.CurisConfig.MODULE_ADDRESS.CurisForum);
return "index/index";
}
}
//compare the servlet request url and redirect to
return "login/landing";
}
@RequestMapping(value="about")
public ModelAndView aboutPage(HttpServletRequest request,HttpServletResponse response) {
Cookie[] cookieArr=request.getCookies();
if(cookieArr==null) {
return new ModelAndView("login/landing");
}
for(Cookie cookie:cookieArr){
System.out.println(cookie.getName());
if(cookie.getName().equals("userInfo")){
String userIdStr=cookie.getValue();
long userId=Long.parseLong(userIdStr);
UserBean userBean=userService.getUserById(userId);
HttpSession session=request.getSession();
session.setAttribute(Constant.SESSION_USER, userBean.getId()+"");
if(userBean.getIsActive()==1){
session.setAttribute(Constant.SESSION_IS_ACTIVE, true);
}else{
session.setAttribute(Constant.SESSION_IS_ACTIVE, false);
}
request.setAttribute("MsgModuleUrl", CurisConfig.CurisConfig.MODULE_ADDRESS.MsgModule);
request.setAttribute("formula", CurisConfig.CurisConfig.MODULE_ADDRESS.CurisForum);
return new ModelAndView("index/index");
}
}
return new ModelAndView("login/about");
}
所以你可以看到我在某种程度上与我返回请求的方式不一致,但我试图看看ModelAndView是否可行,因为String实现不会。