日期:2014-05-17  浏览次数:20813 次

求助!用户已经登录,怎么从后台取出用户的用户名
比如要插入一些数据到数据库中,要插入的有用户名,用户操作时间,物品等等。但是用户名和用户操作时间不在插入页面上输入,而是直接从后台取,要怎么取?

------解决方案--------------------
在登录的时候 使用 request.getSession().setAttribute("user_id",userName);
方法将用户名放入Session中! 

 request.getSession().setAttribute("login_time",new SimpleDateformat("yyyy-MM-dd hh:mm:ss").format(new Date().getDate()));
将登录时间放在Session中
在需要用的时候

String userID= request.getSession()..getSession("user_id");
String loginTime =request.getSession().getSession("loginTime");

这样就可以拿到登录时间和登录者的ID 



手写的 你看下 有可能有地方写错单词了!