Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%ServletContext servletContext = getServletContext();
- InputStream input = getServletContext().getResourceAsStream("/WEB-INF/db.properties");
- if (input != null) {
- InputStreamReader isr = new InputStreamReader(input);
- BufferedReader reader = new BufferedReader(isr);
- PrintWriter writer = response.getWriter();
- String text;
- while ((text = reader.readLine()) != null) {
- /* System.out.println(text + "n"); */
- servletContext.setAttribute(text.split("=")[0], text.split("=")[1]);
- }
- }
- %>
- ServletContext servletContext = getServletContext();
- String driverDB = servletContext.getAttribute("driver").toString();
- String conn_urlDB = servletContext.getAttribute("conn_url").toString();
- String userNameDB = servletContext.getAttribute("userName").toString();
- String passwordDB = servletContext.getAttribute("password").toString();
- DBConnection.getDataBaseProperty(driverDB, conn_urlDB, userNameDB, passwordDB);
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
- <display-name>TouchPoint</display-name>
- <welcome-file-list>
- <welcome-file>Login.jsp</welcome-file>
- </welcome-file-list>
- <servlet>
- <display-name>LoginServlet</display-name>
- <servlet-name>LoginServlet</servlet-name>
- <servlet-class>com.touchpoint.controller.LoginServlet</servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>LoginServlet</servlet-name>
- <url-pattern>/LoginServlet</url-pattern>
- </servlet-mapping>
- <servlet>
- <servlet-name>LogoutServlet</servlet-name>
- <servlet-class>com.touchpoint.controller.LogoutServlet</servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>LogoutServlet</servlet-name>
- <url-pattern>/LogoutServlet</url-pattern>
- </servlet-mapping>
- </web-app>
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
- <display-name>ServletListenerExample</display-name>
- <context-param>
- <param-name>DBUSER</param-name>
- <param-value>pankaj</param-value>
- </context-param>
- <context-param>
- <param-name>DBPWD</param-name>
- <param-value>password</param-value>
- </context-param>
- <context-param>
- <param-name>DBURL</param-name>
- <param-value>jdbc:mysql://localhost/mysql_db</param-value>
- </context-param>
- <listener>
- <listener-class>com.journaldev.listener.AppContextListener</listener-class>
- </listener>
- public class AppContextListener implements ServletContextListener {
- public void contextInitialized(ServletContextEvent servletContextEvent) {
- ServletContext ctx = servletContextEvent.getServletContext();
- String url = ctx.getInitParameter("DBURL");
- String u = ctx.getInitParameter("DBUSER");
- String p = ctx.getInitParameter("DBPWD");
- }}
Add Comment
Please, Sign In to add comment