0
JSF 2.0でのログイン処理に問題があります。私が正しい方向に進んでいるかどうかは分かりません。私は具体的にしたいので、私はどのように私のアプリケーションが動作するかを指摘しますJSF 2.0ログイン+セッションスコープ処理に関する問題
- セッションスコープ付きのログインページ bean。
- は、適切なログイン後、ユーザ は、別のセッションが
- Beanをスコープ 二Beanがデータベース
私の質問は何ですかユーザーに対して2つのセッションを作成しますか?もしそうなら、どうすれば最初のセッションを終了させることができますか?ログインを管理する最良の方法でない場合は、私を修正してください。ここでは、事前
にありがとう
LOGIN BEAN
package main;
import java.io.Serializable;
import java.sql.SQLException;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@SessionScoped
@ManagedBean(name="loginBean")
public class loginBean implements Serializable
{
private String login;
private String password;
public loginBean()
{
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String login() throws ClassNotFoundException, SQLException
{
SQL sql = new SQL(); //class connecting do database
if(sql.login(this.login, this.password) == true)
{
return "yes";
}
else
{
return "no";
}
}
}
ログインページlogin.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
</h:head>
<h:body>
<h:form>
<div id="logowanie" style="margin: auto; max-width: 180px; margin-top: 50px; ">
<table border="0" cellspacing="4" cellpadding="4">
<thead></thead>
<tbody>
<tr>
<td><h:outputText value="login:" /></td>
<td><h:inputText value="#{loginBean.login}" size="10"/></td>
</tr>
<tr>
<td><h:outputText value="password:" /> </td>
<td><h:inputSecret value="#{login.password}" size="10"/></td>
</tr>
<tr>
<td colspan="2"><h:commandButton value="zaloguj" action="#{loginBean.login}" /></td>
</tr>
</tbody>
</table>
</div>
</h:form>
</h:body>
</html>
PANEL BEAN(第2豆)
package main;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@SessionScoped
@ManagedBean(name="panelBean")
public class panelBean implements Serializable{
private String login;
private String password;
FacesContext context = FacesContext.getCurrentInstance();
public panelBean()
{
loginBean Bean = (loginBean) context.getApplication().getVariableResolver().resolveVariable(context, "loginBean");
this.password = Bean.getPassword();
this.login = Bean.getLogin();
Bean.setPassword("");
Bean.setLogin("");
ExternalContext ectx = FacesContext.getCurrentInstance().getExternalContext();
HttpServletResponse response = (HttpServletResponse)ectx.getResponse();
HttpSession session = (HttpSession)ectx.getSession(false);
session.invalidate();
}
}
simplyfied例です
FACES CONFIG
<?xml version='1.0' encoding='UTF-8'?>
<!-- =========== FULL CONFIGURATION FILE ================================== -->
<faces-config version="2.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
<navigation-rule>
<from-view-id>/login.xhtml</from-view-id>
<navigation-case>
<from-outcome>yes</from-outcome>
<to-view-id>/panel.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>no</from-outcome>
<to-view-id>/login.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
ありがとうございます。私はCGIを使用しているので、私は要求範囲を選択しましたbeacause vievスコープはサポートされていません – Szajba