来自另一个java应用程序,我已经将我的属性设置为:
HttpSession session = request.getSession(true);
session.setAttribute("SessionUser", userName);
我不确定如何将特定属性解析为字符串。
String query = "SELECT title, first, last, email FROM member WHERE email="+**??**;
答案 0 :(得分:2)
刚演员:
String username = (String) session.getAttribute("SessionUser");
答案 1 :(得分:1)
您似乎只是将用户的名称添加到会话属性中。
尝试设置整个User对象(在您的情况下是域对象),如下所示:
session.setAttribute("SessionUser", userObj);
然后使用:
获取对象UserObj userObj = (UserObj) session.getAttribute("SessionUser");
然后在您的查询中使用它,如下所示: (假设您在UserObj中有一个getEmail())
String userEmail = userObj.getEmail();
String query = "SELECT title, first, last, email FROM member WHERE email="+ userEmail;
答案 2 :(得分:0)
如果userName属性是String对象,则可以使用
调用它String userName= (String)session.getAttribute("SessionUser");
String query = "SELECT title, first, last, email FROM member WHERE email="+ userName;
还是它的豆子?然后;
UserBean user = (UserBean)session.getAttribute("SessionUser");
String query = "SELECT title, first, last, email FROM member WHERE email="+ user.getUserName();