一、实例化application
public class ServletA extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {ServletContext application = this.getServletContext(); // //GenericServlet提供的方法,得到application
// 以 javax.servlet-api 2.5为例,request为请求实例:
//ServletContext application = request.getSession().getServletContext();
application.setAttribute("name",name);application.getAttribute("name");}
}
二、实例化session
public class ServletA extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {HttpSession session = request.getSession(); //实例化session
}
}