If we are coding a JSP file, we just need to use the embedded "application" object. But how to use it in a Servlet?
+1
A:
The application object references javax.servlet.ServletContext and you should be able to reference that in your servlets.
To reference the ServletContext you will need to do the following:
// Get the ServletContext
ServletConfig config = getServletConfig();
ServletContext sc = config.getServletContext();
From then on you would use the sc object in the same way you would use the application object in your JSPs.
scheibk
2009-04-19 15:42:18
+1
A:
Try this:
ServletContext application = getServletConfig().getServletContext();
John Topley
2009-04-19 15:49:33
+1
A:
The application object in JSP is called the ServletContext object in a servlet; so you can do this to hold a reference to it:
public class MyServlet extends HttpServlet
{
private ServletContext ctx = null;
@Override
public void init(ServletConfig config) throws ServletException {
ctx = config.getServletContext();
}
}
Boiler Bill
2009-04-19 15:51:03
thanks for all of your quick answer! I've get it!
fwoncn
2009-04-19 15:57:55