Timeline for Java web application for sharing temporary notes
Current License: CC BY-SA 3.0
8 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Dec 17, 2017 at 19:26 | comment | added | Mario Santini | Once you defined a JNDI resource you can use dependecy injection in your servlet. There are several ways to do that, I can just point you to a tutoral that show one of those: theopentutorials.com/tutorials/java-ee/servlet/…. The point I raised is that you should inject the DAO in a class that is not the servlet. | |
Dec 17, 2017 at 19:18 | comment | added | Mario Santini | Sorry for the confusion @coderodde, the init-param is for the configuration strings instead of using singletons. For the DAO, you should first configure the JNDI resource in the Context config file, but the details depends on which web container you're using. | |
Dec 17, 2017 at 19:07 | comment | added | coderodde | Would it be good practice to call getInitParameter("myDAOparam") in Servlet.init() and switch on that string plugging in the desired DAO implementation? | |
Dec 17, 2017 at 18:59 | comment | added | coderodde |
I understood that getInitParameter() returns only a String . How should I go about instantiating the servlets with a class implementing a data store interface?
|
|
Dec 17, 2017 at 16:29 | vote | accept | coderodde | ||
Dec 17, 2017 at 16:04 | comment | added | Mario Santini | In web.xml where you define the <servlet> you could provide <init-param>. For DataStore you could use jndi, following the web container documentation. Here an example with Tomcat. Once you have that you could inject in your servlet. | |
Dec 17, 2017 at 14:31 | comment | added | coderodde |
Very good points, thanks! A question, where in my web app should I set the dependencies (such a DataStore object for the servlets)?
|
|
Dec 17, 2017 at 8:48 | history | answered | Mario Santini | CC BY-SA 3.0 |