import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletContext;//和其它的不在一個包 import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; public class X extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session=request.getSession();//得到session ServletContext application =super.getServletContext();//GenericServlet提供的方法,得到application }