jsp在页面获取不到值的方法

自己在做项目的时候,在jsp页面通。过${xxx}获取不到值,困扰了自己好久。

自己jsp页面如下:

controller如下:

 @RequestMapping(value = "/checkLogin",method = RequestMethod.POST)
    public String checkLogin(@RequestParam(value = "userName") String userName, @RequestParam (value = "password") String password,HttpSession session){

        String passwordMd5=DigestUtils.md5DigestAsHex(password.getBytes());//Spring自带的Md5加密
        User user = userService.checkLogin(userName, passwordMd5);
        System.out.println(user.toString());
        if(user!=null){
            /*
            两种方式向session域中存数据
            1、通过HttpSession。
               httpSession.setAttribute(key,value)

            2、通过ModelMap。
                modelMap.addAttribute(key,value)
             */
            session.setAttribute("user",user);

            return "redirect:HomePage1";
        }

        return "user_jsp/user_login";

    }

但是页面就是不显示session中的值。

  • 首先,我忘记在jsp中忘了加 <%page isELIgnored="false"%>,isELIgnored的默认值为true,导致了在jsp页面会把${xxx}解析成正常的文本。
  • 即使加了<%page isELIgnored="false"%>,我在另一个页面又碰到相同的问题,解决如下:在使用Servlet规范的时候,要使用新的规范Servlet3.1,不要使用默认的,可以将web.xml文件修改如下,就能解决问题。

 

你可能感兴趣的:(JSP)