学习笔记

Simple is beautiful.

导航

<2007年9月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

统计

公告

...

常用链接

留言簿(1)

随笔分类(2)

随笔档案(56)

Weblog

搜索

最新评论

评论排行榜

Coding Guidelines for URL Rewriting

There are some general guidelines for how your code should handle URLs in order to support URL rewriting.

  • Avoid writing a URL straight to the output stream, as shown here:
    out.println("<a href=\"/myshop/catalog.jsp\">catalog</a>");

    Instead, use the HttpServletResponse.encodeURL() method, for example:

    out.println("<a href=\""
    + response.encodeURL("myshop/catalog.jsp")
    + "\">catalog</a>");

    Calling the encodeURL() method determines if the URL needs to be rewritten, and if so, it rewrites it by including the session ID in the URL. The session ID is appended to the URL and begins with a semicolon.

  • In addition to URLs that are returned as a response to WebLogic Server, also encode URLs that send redirects. For example:
    if (session.isNew())
      response.sendRedirect (response.encodeRedirectUrl(welcomeURL));

    WebLogic Server uses URL rewriting when a session is new, even if the browser does accept cookies, because the server cannot tell whether a browser accepts cookies in the first visit of a session.

  • Your servlet can determine whether a given session ID was received from a cookie by checking the Boolean returned from the HttpServletRequest.isRequestedSessionIdFromCookie() method. Your application may respond appropriately, or simply rely on URL rewriting by WebLogic Server.

posted on 2007-09-01 11:48 Ecko 阅读(238) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: