java怎么通过servlet获取from的传值查询mysql数据库对应表的数据并显示到jsp页面中? 10

protectedvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServl... protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub String name = request.getParameter("name"); String fullName = request.getParameter("fullName"); try { List userList = findLists(name,fullName); request.setAttribute("userList", userList); request.getRequestDispatcher("/client/listUser.jsp").forward(request, response); } catch (SQLException e){ e.printStackTrace(); } }private List findLists(String name, String fullName) throws SQLException { // TODO Auto-generated method stub Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; try{ //连接数据库 conn = DbUtil.getConnection(); //创建PrepareStatement对象 String sql = "SELECT * FROM user_table where name like ? or fullname like ?"; pstmt = conn.prepareStatement(sql); pstmt.setString(1,"'%" + name +"%'"); pstmt.setString(2,"'%" + fullName +"%'"); //执行查询 rs = pstmt.executeQuery(); //储存查询出来的用户数据 List userList = new ArrayList(); //遍历结果集 while(rs.next()){ int id = rs.getInt("id"); System.out.print(name); String password = rs.getString("password"); String gender = rs.getString("gender"); String phone = rs.getString("phone"); String email = rs.getString("email"); int status = rs.getInt("status"); int roleId = rs.getInt("role_id"); String roleName = rs.getString("roleName"); User user = new User(id, name, password, fullName, gender, phone, email, status); Role role = new Role(roleId, roleName); user.setRole(role); userList.add(user); } return userList; }finally{ DbUtil.close(pstmt, rs, conn); } }表里面有name字段“a”字符数据,但我想找到name里有“a”字符的数据,可是查询不到相应的数据,怎么搞 展开
 我来答
飞鸟侠客双子
2017-05-31
知道答主
回答量:40
采纳率:0%
帮助的人:5.2万
展开全部
 request.getSession().setAttribute("cid", id);
 // 这样在后面就可以通过 session.getAttribute("cid") 来获取,望采纳
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式