按照 BalusC 指南,我尝试创建一个登录系统,以便通过 Servlet 访问我的 JSF 页面,但它不起作用:(
我的登录 Servlet 是:
public class DoLogin extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
creaLogin(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) {
creaLogin(request, response);
}
//This method call the FacesContext and pass login nformation
private void creaLogin(HttpServletRequest request, HttpServletResponse response){
FacesContext facesContext = FaceUtil.getFacesContext(request, response);
//Retrieve login information from get/post callback
String userid=request.getParameter("userid");
String password=request.getParameter("password");
//I create an istance of LoginBean backingbean that manage login information for my JSF page
LoginBean mioBean = (LoginBean) facesContext.getApplication().evaluateExpressionGet(facesContext,
"#{loginBean}", LoginBean.class);
mioBean.setUsername(userid);
mioBean.setPassword(password);
mioBean.externalLogin(); //this method perform all needed operation and intialize all backing beans of my app
//Call ma xhtml page
ConfigurableNavigationHandler nav
= (ConfigurableNavigationHandler)
facesContext.getApplication().getNavigationHandler();
nav.performNavigation("pannello");
}
}
FaceUtil 与 BalusC 在他的示例中显示的相同。
先感谢您
问候