如何从java代码中重定向一个JSF页面
1 示例代码如下:
public static void redirectPage(String szPage)
{
FacesContext context = FacesContext.getCurrentInstance();
javax.faces.application.Application app = context.getApplication();
UIViewRoot view = app.getViewHandler().createView(context, szPage);
context.setViewRoot(view);
context.renderResponse();
} |
2. FacesContext fc = FacesContext.getCurrentInstance(); try {
fc.getExternalContext().redirect(this.getRequest().getContextPath()+"/login.faces"); }
catch (IOException e) { e.printStackTrace(); }
The context line should have been declared before the application line of code
FacesContext context = FacesContext.getCurrentInstance(); javax.faces.application.Application app = context.getApplication();