spring mvc的HttpSession应用实例

来源:互联网 发布:网上银行系统繁忙淘宝 编辑:程序博客网 时间:2024/06/06 07:51

controller:

    @RequestMapping(value = "/auto", method = RequestMethod.GET)
    public @ResponseBody
    AvailabilityStatus getAvailability(@RequestParam String name,Locale locale, HttpSession httpSession) {
        logger.info("Welcome auto! the client locale is " + locale.toString());
        ResourceBundle myResources =
                  ResourceBundle.getBundle("messages", locale);
        String aha = myResources.getString("label.lastname");
        System.out.println( name );
        httpSession.setAttribute("accountBean", this );
        return AvailabilityStatus.notAvailable(aha);
    }


jsp:

        <c:if test="${sessionScope.accountBean111 != null}">
            <p>aaa</p>
        </c:if>

注意在jsp页面中不能有<%@ page session="false" %>