在
applicationJSP中的对象被称为
ServletContext在servlet对象。可以通过继承的
GenericServlet#getServletContext()方法使用。您可以在servlet的任何地方(
init(ServletConfig)方法除外)调用此函数。
public class YourServlet extends HttpServlet { @Override public void init() throws ServletException { ServletContext ctx = getServletContext(); // ... } @Override public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { ServletContext ctx = getServletContext(); // ... } @Override public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { ServletContext ctx = getServletContext(); // ... }}


