📄 loginbean.java
字号:
package com.wxd.common.popedom.presentation;
import java.io.IOException;
import javax.faces.application.Application;
import javax.faces.application.FacesMessage;
import javax.faces.component.html.HtmlInputSecret;
import javax.faces.component.html.HtmlInputText;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.wxd.common.popedom.service.LogService;
import com.wxd.common.popedom.service.ServiceFactory;
import com.wxd.util.MessageFactory;
public class LoginBean {
private HtmlInputText userid;
private HtmlInputSecret password;
public HtmlInputText getUserid() {
return userid;
}
public void setUserid(HtmlInputText userid) {
this.userid = userid;
}
public HtmlInputSecret getPassword() {
return password;
}
public void setPassword(HtmlInputSecret password) {
this.password = password;
}
public String login() {
LogService logService = ServiceFactory.getLogService(FacesContext.getCurrentInstance());
boolean result = logService.isValidUser(this.getUserid().getValue()
.toString().trim(), this.getPassword().getValue().toString()
.trim());
if (result)
return "success";
else {
FacesMessage msg = MessageFactory.getMessage(FacesContext.getCurrentInstance(),
"error_password", "");
msg.setSeverity(FacesMessage.SEVERITY_ERROR);
FacesContext.getCurrentInstance().addMessage(null, msg);
return "failure";
}
}
public String logout() throws IOException {
ExternalContext ectx = FacesContext.getCurrentInstance()
.getExternalContext();
HttpServletResponse response = (HttpServletResponse) ectx.getResponse();
// HttpSession session = (HttpSession)ectx.getSession(false);
// session.invalidate();
// FacesContext ctx = FacesContext.getCurrentInstance();
// Application app = ctx.getApplication();
// app.getNavigationHandler().handleNavigation(ctx, "/index.jsp", "main");
// To avoid using the navigation handler you could also use...
response.sendRedirect("../index.jsp");
FacesContext.getCurrentInstance().responseComplete(); //jsf1.2不能返回null,必须使用此方法重定向
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -