日期:2014-05-17 浏览次数:20759 次
public class Demo6 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//两种获取servletContext对象的方式
ServletContext context = this.getServletConfig().getServletContext();
ServletContext context1 = this.getServletContext();
//servlet6带数据给servlet7(用context对象实现数据共享)
context1.setAttribute("name", "zhangsan");
}
public class Demo7 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ServletContext context = this.getServletContext();
//context.setAttribute("data", 123);
System.out.println(context.getAttribute("name"));
}