jsp页面之间通过servelt调用DAO方法,让DAO回传入的值,通过servlet调到转入的页面

来源:互联网 发布:nc57 数据字典 微盘 编辑:程序博客网 时间:2024/05/17 22:21

2014.9.1开始接触jsp


<pre name="code" class="plain"> person.jsp
 <form action="aaa" method="post">  //这个aaa是在web.xml配置文件中配置             <p> 姓名<input  type="text"  name="t1"> <input type="submit" value="提交"></p>              </form>


MySerVlet.jsp
protected void doPost(HttpServletRequest request, HttpServletResponse resp)throws ServletException, IOException {// 怎么从servlet中的接受的name值 传入到其他页面响应的位置request.setCharacterEncoding("utf-8");// 防止接受的页面的值传入java中会乱码String name1 = request.getParameter("t1");// 接受从person的值Action a = new Action();ArrayList<Student> list = a.qurey(name1);// 接受action中的查询方法request.setAttribute("list", list);  //存储从Action中查出来的Student集合// 转向request.getRequestDispatcher("seek.jsp").forward(request, resp);然后再传入seek.JSP}


seek.jsp
<%                   ArrayList<Student> list = (ArrayList<Student>)request.getAttribute("list");                   for(Student aa:list){                   %>                    <tr>                   <td><%=aa.getName()%></td>                   <td><%=aa.getSex() %></td>                   <td><%=aa.getAge() %></td>                   <td><%=aa.getAddres()%></td>                   </tr>                            <%                   }                    %>   







0 0