<#else>
summercool框架对Cookies封装
cookie-configurer.xml
xmlns:context=\xmlns:util=\ xsi:schemaLocation=\ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd\> 在上面这个配置文件中,最重要的是CookieConfigurer类配置,如下: 说明: 1) domain: cookie存放在的域名(笔者建议设置为一级域名,这样二级域名的 应用也可以获取和共享一级域名的cookie) 2) lifeTime:设置cookie的有效期 3) name:服务端的cookie名称,因为开发者在使用时,要知道设置了哪个 cookie 4) clientName:相对于服务端的cookie名称,这个是客户端的cookie名称。 5) encrypted:是否进行加密处理;设置了此属性,CookieConfigurer类会自 动对该cookie进行加密和解密。 如下应用举例: publicstaticvoidwriteCookie(HttpServletRequestrequest, UserDOuserDO) { if (request == null || userDO == null) { thrownewIllegalArgumentException(); } CookieModulejar = (CookieModule)request .getAttribute(CookieModule.COOKIE); if (jar == null) { thrownewNullPointerException(); } jar.remove(CookieConstants.MANAGER_ID_COOKIE); jar.remove(CookieConstants.MANAGER_PWD_COOKIE); jar.remove(CookieConstants.MANAGER_UNAME_COOKIE); jar.set(CookieConstants.MANAGER_ID_COOKIE, userDO.getId().toString()); try { jar.set(CookieConstants.MANAGER_UNAME_COOKIE, URLEncoder.encode(userDO.getUserName(), \)); } catch (UnsupportedEncodingExceptione) { } jar.set(CookieConstants.MANAGER_PWD_COOKIE, userDO.getPassword()); } 说明:summercool框架已经对cookies进行了封装,在配置文件配置完成后就可以直接使用了 只要通过reqeust对象就可以直接设置和获取cookie的相关信息了。 所有的用户登录信息最好不用要session实现,因为session还要解决分布式的问题。建议登录信息全部都存放在cookie里面 是非常好的,因这样不仅可以实现登录信息的保存而且大大降低了开发难度;相关于变相的实现了无状态登录。 summercool框架对UrlRewrite封装 1) 比如说我们有这样的一个需求,所有的页面都要通过/item/1.htm这样的url 地址来访问“产品的详细页面” 2) 像上面这样的配置规则,我不需要多于的代码编写,可以自动生成上面这样 风格的url或是自定义的url风格 3) 上面成生的url风格中,我们还可以提取“1”这样的参数或是url中的参 数可以直接提取出来 请看url-configurer.xml的配置: xmlns:xsi=\xmlns:context=\ xmlns:util=\ xsi:schemaLocation=\ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd\>