【发布时间】:2010-09-05 21:37:09
【问题描述】:
我正在为我的 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";
}
}
我得到的关于会话的概念非常简单明了。我必须在有效的用户输入后创建一个会话对象并将用户名添加到该对象,单击注销时销毁该对象。但我以前没有参加过会议。我的意思是,我不知道创建会话变量的语法。
如何在这里创建会话对象?
任何建议都会更感激!!!
提前致谢!!!
【问题讨论】:
-
什么是“Java 代码”?它在哪个班?它是一个 servlet 吗?
-
@skaffman:哦,对不起。我现在会更新我的问题。
-
这并没有真正的帮助...
LoginAuthentication是什么,它与其他任何东西有什么关系? -
@skaffman:它只是一个类名。我删除了其他方法。也许我不知道如何根据用途命名一个类。