问题:
HttpSession session 无法导包
问题在于servlet-api.jar,tomcat中自带这个jar包,所以在Eclipse中从来没配置过,但是没想到idea上要手动将此jar包引入工程。
@RequestMapping("/login.do")
public String login(String name ,String pwd,ModelMap map, HttpSession session){
if(userService.login(name,pwd)){
session.setAttribute("userName", name);
return "redirect:/main/index.do";
}else{
map.addAttribute("msg","用户:"+name+" 登陆失败,密码为:"+pwd);
return "error";
}
}
解决方法:
第一步:点击打开File-->Project Structure

第二步:Dependences--> +号 -->JARs or Directories,找到自己安装的Tomcat目录下lib/servlet-api.jar,点击添加

第三步:apply,按住alt + Enter快捷键自动导包
本文介绍在IDEA开发环境中,如何解决HttpSession无法导入的问题,详细步骤包括在项目结构中添加Tomcat的servlet-api.jar依赖,确保HttpSession能够正常工作。
3322

被折叠的 条评论
为什么被折叠?



