无上的在下
2021-11-20 22:19
采纳率: 100%
浏览 21

前台页面中什么标签可以获取servlet中传过来的数据?

Servlet中

   public void findStudent2(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
    HttpSession session = request.getSession();
    User student1  = (User)session.getAttribute("user");
    //1.获取id
    String id = Integer.toString(student1.getId());
    
    //2.调用Service查询
    StudentService service = new StudentServiceImpl();
    Student student = service.findStudentById(id);

    //3.将User存入request
    request.setAttribute("student",student);
    //4.转发到student_info.jsp
    request.getRequestDispatcher("/student_info.jsp").forward(request,response);
}

前台页面中

          <table class="table table-striped table-hover" style="margin: 10px;">
                       
                            <tr>
                                
                                <td>学号</td><td>${student.id}</td> 
                            </tr>
                            <tr>
                                <td>姓名</td><td>${student.name}</td>
                            </tr>
                            <tr>
                                <td>性别</td><td>${student.gender}</td>
                            </tr>
                            <tr>
                                <td>年龄</td><td>${student.age}</td>
                            </tr>
                            <tr>
                                <td>班级</td><td>${student.classno}</td>
                            </tr>
                            <tr>
                                <td>电话</td><td>${student.phone}</td>
                            </tr>
                            <tr>
                                <td>邮箱</td> <td>${student.email}</td>
                            <tr>
                     
                            </tr>
                                                  
                    </table>

想要将servlet中的student类传到前台页面,然后在table中展示信息。
类似这种

img

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题