Webアプリケーションのログインページを作成しています。新しいユーザーがログインするたびにセッションオブジェクトを作成したい。セッションの概念は知っているが、以前はそれを使用していなかった。簡単なクラスでできますか?または、サーブレットに移動する必要があります。単純なクラス手段でそれを行う場合、セッションオブジェクトを作成する方法。
これが私のシナリオです...
HTMLコード:
<table>
<tr>
<td>User Name: </td><td><input id="uName" class="required" type="text"
size="5" /></td>
</tr>
<tr>
<td>Password: </td><td><input id="pwd" class="required" type="text" size="5"
onclick="login()"/></td>
</tr>
</table>
JSコード:
function login(){
var userDetails = { uName : null, pwd : null };
dwr.util.getValues(userDetails);//Yes, i am using DWR.
LoginAuthentication.doLogin(userDetails, loginResult);
}
function loginResult(nextPage){
window.location.href = nextPage;
}
Javaコード:
public class LoginAuthentication
{
public String doLogin(User user) throws SQLException, ClassNotFoundException{
String userName = user.getUserName();
boolean loginResult = verifyUser(user);//Another method that verifies user details with the DB.
if (loginResult == true){
/* Here I have to create session object,
and i want to add the current username in that object. How to do it.*/
return "MainPage.html";
}
else{
return "loginRetryPage.html";
}
}
セッションについて私に与えられた概念は非常に単純で明確です。有効なユーザー入力の後にセッションオブジェクトを作成し、そのオブジェクトにユーザー名を追加する必要があります。ログアウトがクリックされたときにオブジェクトを破棄します。しかし、私は以前にセッションに取り組んでいませんでした。つまり、セッション変数を作成するための構文がわかりません。
ここでセッションオブジェクトを作成するにはどうすればよいですか?
どんな提案ももっと感謝するでしょう!!!
前もって感謝します!!!