在jsp页面中我这样写的<%@page import="com.entity.User"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
User user=new User();
List<User> list=(List<User>)request.getSession().getAttribute("list");
%><body>
<%for(User user:list){ %>
编号 <input type="text" name="id" value="<%=user.id %>"><br>
用户名 <input type="text" name="name" value="<%=user.name %>"><br>
密码<input type="text" name="password" value="<%=user.pass %>"><br>
<%} %>
</body>但是在for循环那报错使jsp页面无法编译servlet里public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
List<User> list = UserService.getInstance().selectAll();
HttpSession session=request.getSession();
if(list == null){
System.out.println("查找失败");
}else{
System.out.println("查找成功!");
System.out.println("list里的值"+list.get(1).getName());//能输出
session.setAttribute("list", list);
response.sendRedirect(request.getContextPath()+"/user/allUser.jsp");
}
}
添加回答
举报
0/150
提交
取消