ServletContext « API « JSP-Servlet Q&A

1. ServletContext.getRequestDispatcher() vs ServletRequest.getRequestDispatcher()


getRequestDispatcher(String path) of the ServletRequest interface cannot extend outside the current servlet context
where as
getRequestDispatcher(String path) of the ServletContext can use the ...

2. single method in getRequestDispatcher() in ServletRequest and ServletContext interfaces

HI I like to know there is a single method called getRequestDispatcher() in ServletRequest and ServletContext interfaces. What is the difference?

3. Simple Servlet Question on ServletConfig instantiation

Apparently the following is generating a loop(the GenericServlet class is calling the subclass's init())

public void init() throws ServletException {

  ServletConfig c = this.getServletConfig();

I'm probably just doing this ...

4. When does the ServletContext return a null RequestDispatcher?

The api for ServletContext#getRequestDispatcher() says:

This method returns null if the ServletContext cannot return a RequestDispatcher.
Returns: a RequestDispatcher object that acts as a wrapper ...

5. JPEG file in WEB-INF returned as null by ServletContext#getResource()

Good day! I am trying to output a JPG file contained in the web application to the user using the following code:

public class JpegOutput extends HttpServlet {

    protected void doGet(HttpServletRequest ...

6. ServletContextListener threads

I'm currently having an issue with stopping a background thread in a webachive. I currently tie it in the war's deployment, and destroy it when the archive is un-deployed. The threads ...

7. Unterminated String Literal from getServletContext().getRealPath("/") in JSP

This is an error that came up after I got a previous question here answered. Essentially I'm trying to bring the absPath of the folder with me so I can ...

8. Possible to Store a HashMap in the ServletContext?

Is it possible to store a HashMap into the ServletContext in Java? When I go to get the attribute back it's a there a way to cast it back ...

9. ServletContext attribute is null

The attribute repository returns null.

public class BaseServlet extends HttpServlet {
    protected MyPersistentManager getPersistentManager(){
        return (MyPersistentManager) getServletContext().getAttribute("repository");
I am ...

10. Why is default constructor required for ServletContextAttributeListener?

I created a class that implemented ServletContextAttributeListener without the default constructor and the container complained: SEVERE: Error configuring application listener of ..... java.lang.InstantiationException: ... So I created a default constructor in addition to parameterized ...

11. Store a collection in a ServletContext attribute?

I'm using Servlets and I'm trying to .setAttribute an ArrayList. There are no compile-time errors, but when I run it it says that I can't cast a boolean to an ArrayList. ...

12. How can I print a servlet context attribute in EL?

Is there a way I can get a attribute set in ServletContext in EL so that it ends up as a JavaScript variable? I am setting it as

context.setAttribute("testing.port", "9000");
I tried retrieving ...

14. difference between pagecontext and servletcontext

Kesava, You've posted lots of questions to different forums. They are basic questions and you should be able to find out the answers for yourself by reading a Java book, searching through the archives of Java Ranch, or using Google. People here at Java Ranch enjoy answering questions, but we're not here to do your homework for you! If you have ...

15. Diffenrence between application and servletConfig - servletcontext

Hello, I want to clarify the difference between using application objects [getattribute - setattribute] and the servletconfig - servletcontext objects. Please note that in my web application i create an init class called from the web.xml this class implement the servletcontextListener like the following code : ======================= public class Jcls_Init implements ServletContextListener { public void contextInitialized(ServletContextEvent sce) { sce.getServletContext().setAttribute("config","1"); } } ...

16. ServletContext vs. PageContext

17. ServletContext and ServletConfig

18. PageContext and servletContext

20. ServletContext and RequestDispatcher?

27. Attribute in ServletContext

28. ServletContext and ServletConfig

29. ServletContext and Attributes

30. ServletConfig and ServletContext

34. servletContext, servletConfig

35. ServletContext's getContext() method

36. about ServletContext and ServletConfig

38. ServletConfig vs ServletContext

39. servletContext& ServletConfig

40. servletContext Vs servletConfig

41. ServletConfig and ServletContext

43. What is the difference between ServletContext and ServletConfig

generally it's a belief that there is one servletcontext per application. but in reality this is the case when your application is running on one jvm. if your application is running on more than one jvm's than you have more than one servletcontext objects for your application (one servlet context object per jvm). but your servlet config object is always one ...

44. servletcontext-attribute

45. servletcontext and servletconfig

47. getContext method in ServletContext

51. ServletContext Vs ServletConfig

52. difference between the getContextPath of ServletRequest and ServletContext

Thank you Bauke for the prompt reply. Can the values returned by the HttpServletRequest#getContextPath() and ServletContext#getContextPath() be different in any case? Generally, we give the context path in the application.xml(In case of JBoss and Websphere).Lets say for a Test.war, we give the context path as /Test in the application.xml. Now a call to ServletContext#getContextPath() made by a Servlet in Test.war, would ...

53. How to get ther servlet name from the Httprequest / servletContext

Thanks for your reply. I have a requirement , to create a new request in the server side , based on the original request. So before making a URL connection. I need to check if the server name and port is same as the original request then I need to check the if the servlet name is available in the local ...

54. RequestDispatcher in servletcontext

55. About ServletContext and ServletConfig

56. ServletContext, its attribute to be shared for all over the Servlet?

public void setDBContext() { // main initiated location for db.xml // to be shared for all servlets String location = "/WEB-INF"; String newLocation = getServletContext().getRealPath(location); getServletContext().setAttribute("dbxml-location", newLocation); // to obtain it use below code //String n = getServletContext().getAttribute("dbxml-location").toString(); } // always important to obtain the db location! public String getDBContext() { String path = getServletContext().getAttribute("dbxml-location").toString(); return path; }