Ticket #79 (new enhancement) — at Version 1
老程序员的页面跳转写法
| Reported by: | liaojunqiang | Owned by: | |
|---|---|---|---|
| Priority: | trivial | Milestone: | |
| Component: | 系统相关 | Version: | |
| Keywords: | http 页面跳转 | Cc: | |
| Due Date: | 17/01/2012 |
Description (last modified by liaojunqiang) (diff)
整理接口的时候发现一个老程序员写的页面跳转方法,觉得挺有趣的,所以在这里分享一下。
response.setStatus(301);
response.setHeader("Location", newurl);
response.setHeader("Connection", "close");
一般程序员是这样写的
response.sendRedirect(newurl);
第2种比第1种要好,因为:
1,代码更加容易阅读,简洁。
2,兼容老式浏览器,有些浏览器是不支持自动重定向,可能现在也不多见了。
3,能够把相对URL转换成绝对URL,可移植性强。
如果觉得第一种比第二种好的童鞋请指教,欢迎拍砖...
Note: See
TracTickets for help on using
tickets.
![(please configure the [header_logo] section in trac.ini)](http://www1.pconline.com.cn/global/2008/images/jss/m_logo091125.jpg)