验证用户登录凭据后,我正在尝试创建会话。我导入了以下内容:
import javax.servlet.http.HttpSession;
我正在使用以下代码:
HttpSession session = request.getSession();
session.setAttribute("sessionName","sessionValue");
但是,我收到以下有关的错误request
request cannot be resolved.
我的完整代码:
package com.q1labs.qa.xmlgenerator.controller.managesession;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import javax.servlet.http.HttpSession;
import com.q1labs.qa.xmlgenerator.model.db.DbLoginQueries;
public class Login {
private DbLoginQueries query = new DbLoginQueries();
public String login(String username, String password) throws SQLException, FileNotFoundException, ClassNotFoundException, IOException{
String returnUrl = "";
//Code verifiying users credentials (Code has been removed)
//If valid is true then credentials are correct
if(valid == true){
//If credentials are correct then create a session
HttpSession session = request.getSession();
session.setAttribute("sessionName","sessionValue");
returnUrl = "home.jsp";
}else{
returnUrl = "index.jsp";
}
return returnUrl;
}
}