为什么取不到session的值

J2EE 码拜 8年前 (2016-03-18) 1104次浏览
一、service层代码:
//根据dao 和bean 层来的;上面两层没问题
//查询全部
public List<Dept> getDepts(){
//做为测试使用
List<Dept> list=new ArrayList<Dept>();
list.add(new Dept(10,”开发部”,”北京”));
list.add(new Dept(20,”测试部”,”上海”));
list.add(new Dept(30,”客户部”,”深圳”));
list.add(new Dept(40,”销售部”,”西安”));
return list;
}
二、在action层中取到service的方法
private DeptService deptService=new DeptService();
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//获取用户提交的请求,确定调用逻辑层的方法
List<Dept> depts=deptService.getDepts();
//封装数据到访问范围内
HttpSession session=request.getSession();
session.setAttribute(“depts”,depts);
//跳转页面
response.sendRedirect(“dept.jsp”);
}
三、jsp页面:
<%@ page language=”java” import=”java.util.*” pageEncoding=”UTF-8″
%>
<%@ page import=”com.cc.bean.Dept” %>
<%@ taglib prefix=”c” uri=”http://java.sun.com/jsp/jstl/core” %>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html>
<head>
<title>My JSP “dept.jsp” starting page</title>
</head>
<body>
本人是页面
<c:forEach items=”${sessionScope.depts}”  var=”d”>
${d.deptno}| ${d.dname}| ${d.loc}<br/>
</c:forEach>

</body>
</html>
四、页面:http://localhost:8080/JSTL/dept.jsp, 什么都没传过来

解决方案

10

可以啊 没问题啊……你的路径是怎么输入的….

30

你要在你的地址栏上输入你在web.xml的url-pattern的那个servlet的那个路径….直接输入你的jsp路径当然取不到

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明为什么取不到session的值
喜欢 (0)
[1034331897@qq.com]
分享 (0)