을 로그 아웃 할 수없는 것은 내가 index.xhtml
에서 사용하는 내 템플릿입니다. 등록 및 로그인 작업은 정상적으로 이루어 지지만 로그 아웃은 내 인생에서 효과가 없을 것입니다.JSF- 여기
@ManagedBean
@ViewScoped
public class UserController {
// http://stackoverflow.com/a/10691832/281545
private User user;
@EJB // do not inject stateful beans !
private UserService service;
public User getUser() {
return user;
}
@PostConstruct
void init() {
// http://stackoverflow.com/questions/3406555/why-use-postconstruct
user = new User();
}
public String login() {
FacesContext context = FacesContext.getCurrentInstance();
try {
System.out.println("Pass :" + user.getPassword());
user = service.find(user.getUsername(), user.getPassword());
context.getExternalContext().getSessionMap().put("user", user);
return "/index.xhtml?faces-redirect=true";
} catch (NoResultException e) {
context.addMessage(null, new FacesMessage(
FacesMessage.SEVERITY_ERROR, "Unknown login, please try again",
null));
return null;
}
}
public String register() {
FacesContext context = FacesContext.getCurrentInstance();
user = service.register(user);
if (user.getIduser() == 0) {
context.addMessage(null, new FacesMessage(
FacesMessage.SEVERITY_ERROR, "Registration failed", null));
return null;
}
context.getExternalContext().getSessionMap().put("user", user);
return "/index.xhtml?faces-redirect=true";
}
public String logout() {
FacesContext.getCurrentInstance().getExternalContext()
.invalidateSession();
return "/index.xhtml?faces-redirect=true";
}
}
그래서 로그인 버튼을 인덱스에 저를 리디렉션 내 로그인 이름을 표시하고 등록은 내가 You are logged in as <username>
바라보고 왼쪽 오전 로그 아웃 버튼을 쳤을 때 인덱스가 새로운 등록 된 사용자로 로그인에 나를 보낸다있다. 이 단지 인덱스 페이지 및 등록 페이지는
편집 앱에 다음 index.xhtml
:
<ui:composition template="/WEB-INF/xhtml/template.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:define name="title">All Times Classics - Welcome</ui:define>
<ui:define name="content">
<h1 style="text-align: center">Welcome to All Times Classics</h1>
You can <a href="register.xhtml">Register</a> if you want to enjoy all
the goodies we have to offer.
</ui:define>
</ui:composition>
정의하십시오 * * 내 인생에 대해 작동하지 않습니다 로그 아웃. 특정 문제는 무엇입니까? 메서드가 실행되지 않고 메서드가 실행되지만 세션이 아직 살아 있습니까? –
@LuiggiMendoza : 예 죄송합니다 : 편집 됨 –
설명 : 로그 아웃 방법의 실행을 점검 할 수 있습니까? –