What is the difference between init param and context param




















Servlet init parameters are for a single servlet only. Nothing outside that servlet can access that. Any servlet or JSP in that web application can access context init parameter.

Login using GitHub Register. Ask a Question. Please log in or register to add a comment. Please log in or register to answer this question. If you have any data which doesn't change frequently you can store it in one of them. The trick is to realize that you're not "creating", "instantiating", or "initializing" an interface.

You are simply defining a variable as being something that you know implements that interface. You are essentially telling other programmers working on this code that for the rest of this method, you are only interested in the fact that myDoc is a Doc i.

This can make programming simpler because the IDE's auto-complete will now only show you the methods that are defined by this interface, rather than everything that a SimpleDoc is capable of doing. Imagine that in the future you want to expand your functionality so that you could have different implementations of Doc depending on some input.

Rather than creating the SimpleDoc explicitly, you say:. So if you want to get access to global values from anywhere within the application without explicitly passing those values, you need to use Context Init parameters. This context param is available to all parts of the web application and it can be retrieved from the Context object.

For instance, getServletContext. From a JSP you can access the context parameter using the application implicit object. For example, application. I have initialized my PersistenceContext.

Every servlet will have access to the context variable. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 6 years, 9 months ago. Active 2 years, 1 month ago. Viewed k times. Improve this question. That question no-where discusses the difference between those two params.. It's just about properties loaded in the two contexts..



0コメント

  • 1000 / 1000