我正在为我的 Web 应用程序创建一个登录页面。每当新用户登录时,我都想创建一个会话对象。我知道会话的概念,但我以前没有使用过。我可以用一个简单的课程来做吗?或者,我必须转移到 servlet。如果我用简单的类方法来做,如何创建会话对象。
这是我的场景...
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";
}
}
给我的关于会话的概念非常简单明了。我必须在有效的用户输入后创建一个会话对象并将用户名添加到该对象,单击注销时销毁该对象。但我以前没有参加过会议。我的意思是,我不知道创建会话变量的语法。
我该如何在这里创建会话对象?
任何建议将更加感激!
提前致谢!!!