Readers: 1040 | Updated: 01-26

Response的sendRedirect实现JSF内的URL重定向

Translate Into:

folder-green-parent-48x48 JavaServer Face(JSF)内置了HttpServletResponse,所以不可以直接在JSF的Bean内使用sendRedirect之类的重定向函数。花了N多的时间查资料,发现误导性的文章比较多,为了有同样需要的人少浪费点时间在这身上,这里把测试通过的方法记录一下:

●导入Servlet包
import javax.servlet.http.*;

●加入下面的取得HttpServletResponse的函数:

protected HttpServletResponse getResponse() …{
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) facesContext
   .getExternalContext().getResponse();
return response;
}
●在需要重定向的地方加入下面代码
response.sendRedirect(“sample.jsp”);
facesContext.responseComplete();  // 这一句很重要
return null;
注:最后的return看自己的需要返回

Related Post




From The Blogs

b5media Lifestyles Channel Feed

04-08
Health and response to cancer treatment [GenBetween]
“How long do they have?” is a complicated question that cancer patients and their families frequently ask their doctors.With older adults, who comprise a more than half of cancer patients, physicians ... 查看全文

Copyblogger

04-20
Give More Than Words for Extreme Reader Response
American rock band Extreme released the ballad More than Words in 1990. The romantic lyrics blended with melodic acoustic guitar soon became a huge hit, as the song raced up the charts all the way to ... 查看全文

The Corner

04-09
Response to TJ
After viewing today's segment of the Uncommon Knowledge interview with Silicon Valley entrepreneur, libertarian, disciple of Milton Friedman, and all-around buccaneer T. J. Rodgers, Craig Good, our fa... 查看全文

JavaEye博客

04-09
struts与JSF的集成
网站: JavaEye 作者: wanglihu 链接:http://wanglihu.javaeye.com/blog/180599 发表时间: 2008年04月08日声明:本文系JavaEye网站... 查看全文

Latest postings for The Lounge

04-11
USB KVMs - response time?
I just got a 2 port kvm, and I didn't spend much on it. 20 bucks at newegg. However, it takes literally 2 to 3 seconds when toggling between the machines which, of course, seems like an eternity when ... 查看全文

b5media Business Channel Feed

04-12
Washington’s AG Offers Initial Response to Amazon/BookSurge Issue [The Golden Pencil: The Freelance Writer\'s Resource]
Although PODdyMouth is optimistic about the initial response of the Attorney Generals office in Washington State about the Amazon/BookSurge issue, Im not impressed - it sounds like the usual political... 查看全文

JavaEye博客

04-15
jsf-自定义转换器
网站: JavaEye 作者: 可爱多 链接:http://xzxzy1982.javaeye.com/blog/182913 发表时间: 2008年04月15日声明:本文系JavaEye网站发布的原... 查看全文

JavaEye博客

04-17
做JSF很久了,我也说说JSF的缺点
网站: JavaEye 作者: upheart 链接:http://upheart.javaeye.com/blog/183613 发表时间: 2008年04月17日声明:本文系JavaEye网站发布... 查看全文

JavaEye博客

04-17
jsf-自定义验证器
网站: JavaEye 作者: 可爱多 链接:http://xzxzy1982.javaeye.com/blog/183128 发表时间: 2008年04月16日声明:本文系JavaEye网站发布的原... 查看全文

b5media Business Channel Feed

04-19
Give More Than Words for Extreme Reader Response [Copyblogger]
American rock band Extreme released the ballad More than Words in 1990. The romantic lyrics blended with melodic acoustic guitar soon became a huge hit, as the song raced up the charts all the way to ... 查看全文
More Articles