我在这里有工作代码,可以从我的用户和位于 oracle 数据库中的用户信息表中提取我需要的所有信息:
try
{
conn = DB_Admin.getConnection();
pstmnt = conn.prepareStatement("SELECT u.username, u.password, ui.user_id, " +
"ui.f_name, ui.l_name, ui.email, ui.dob FROM users u " +
"JOIN user_info ui ON ui.user_id = u.user_id " +
"WHERE u.username = ? AND u.password = ?");
pstmnt.setString(1, username);
pstmnt.setString(2, password);
rs = pstmnt.executeQuery();
boolean exists = rs.next();
...
我有一个 servlet,我试图在他/她登录后显示用户的名字:
String username = request.getParameter("username").toString();
String password = request.getParameter("password").toString();
User user1 = new User(username, password);
User user2 = new User(username,password, user1.getF_name(), user1.getL_name(), user1.getEmail(), user1.getDob());
//HttpSession session = request.getSession();
//session.setAttribute("f_name", user1.getF_name());
boolean valid = ud.login(username, password);
try{
if(!valid)
{
// request.setAttribute("var", companies);
response.sendRedirect("login.html");
logger.warn("Login Servlet : " + username + " has failed at logging in");
}
else
{
//response.sendRedirect("index.jsp");
request.setAttribute("f_name",user2.getF_name());
RequestDispatcher rd = request.getRequestDispatcher("index.jsp");
rd.forward(request, response);
logger.info("Login Servlet : " + username + " has logged in");
}
}
catch (Exception ex) { out.println(ex.getMessage()); }
在我的 User 类中,我有所有字段的 getter 和 setter:“f_name、email 等”。
我知道这段代码写的不正确,而且我的欢迎页面上一直有一个“空”值。