String encodeURL(String url)
Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged.
在客户端禁用了cookie后,如果不用这个方法来ecnode一下URL,那么session就无法使用。
加了此方法后会在url后面追加jsession=*******的信息,也就是追加session ID。
jsession:会话cookie的名字
O_Reilly书籍对此问题的建意
I recommend that you take the time to add encodeURL( ) calls for all references up front, even if you know
that all your current users have browsers that support cookies. One day you may want to extend the user
base and lose control over the browsers they use. It's also common that users disable cookies in fear of Big
Brother watching. Yet another reason to prepare for URL rewriting from the beginning is to support new types
of clients that are becoming more and more common, such as PDAs and cell phones. Cookie support in these
small devices is not a given.
知识点扩展:
Java代码
1.protected Session doGetSession(boolean create) 2.{ 3. … 4. // Creating a new session cookie based on that session 5. if ((session != null) && (getContext() != null) 6. && getContext().getCookies()) 7. { 8. Cookie cookie = new Cookie(Globals.SESSION_COOKIE_NAME, 9. session.getIdInternal()); 10. configureSessionCookie(cookie); 11. response.addCookieInternal(cookie); 12. } 13. 14. if (session != null) 15. { 16. session.access(); 17. return (session); 18. } 19. else 20. { 21. return (null); 22. } 23.} 24. 25.protected void configureSessionCookie(Cookie cookie) 26.{ 27. cookie.setMaxAge(-1); 28. String contextPath = null; 29. if (!connector.getEmptySessionPath() && (getContext() != null)) 30. { 31. contextPath = getContext().getEncodedPath(); 32. } 33. if ((contextPath != null) && (contextPath.length() > 0)) 34. { 35. cookie.setPath(contextPath); 36. } 37. else 38. { 39. cookie.setPath("/"); 40. } 41. if (isSecure()) 42. { 43. cookie.setSecure(true); 44. } 45.}