Guest User

Untitled

a guest
Nov 2nd, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. <%ServletContext servletContext = getServletContext();
  2. InputStream input = getServletContext().getResourceAsStream("/WEB-INF/db.properties");
  3. if (input != null) {
  4. InputStreamReader isr = new InputStreamReader(input);
  5. BufferedReader reader = new BufferedReader(isr);
  6. PrintWriter writer = response.getWriter();
  7. String text;
  8. while ((text = reader.readLine()) != null) {
  9. /* System.out.println(text + "n"); */
  10. servletContext.setAttribute(text.split("=")[0], text.split("=")[1]);
  11.  
  12. }
  13. }
  14. %>
  15.  
  16. ServletContext servletContext = getServletContext();
  17. String driverDB = servletContext.getAttribute("driver").toString();
  18. String conn_urlDB = servletContext.getAttribute("conn_url").toString();
  19. String userNameDB = servletContext.getAttribute("userName").toString();
  20. String passwordDB = servletContext.getAttribute("password").toString();
  21. DBConnection.getDataBaseProperty(driverDB, conn_urlDB, userNameDB, passwordDB);
  22.  
  23. <?xml version="1.0" encoding="UTF-8"?>
  24. <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">
  25. <display-name>TouchPoint</display-name>
  26.  
  27. <welcome-file-list>
  28. <welcome-file>Login.jsp</welcome-file>
  29. </welcome-file-list>
  30. <servlet>
  31. <display-name>LoginServlet</display-name>
  32. <servlet-name>LoginServlet</servlet-name>
  33. <servlet-class>com.touchpoint.controller.LoginServlet</servlet-class>
  34. </servlet>
  35. <servlet-mapping>
  36. <servlet-name>LoginServlet</servlet-name>
  37. <url-pattern>/LoginServlet</url-pattern>
  38. </servlet-mapping>
  39. <servlet>
  40. <servlet-name>LogoutServlet</servlet-name>
  41. <servlet-class>com.touchpoint.controller.LogoutServlet</servlet-class>
  42. </servlet>
  43. <servlet-mapping>
  44. <servlet-name>LogoutServlet</servlet-name>
  45. <url-pattern>/LogoutServlet</url-pattern>
  46. </servlet-mapping>
  47. </web-app>
  48.  
  49. <?xml version="1.0" encoding="UTF-8"?>
  50. <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">
  51. <display-name>ServletListenerExample</display-name>
  52.  
  53. <context-param>
  54. <param-name>DBUSER</param-name>
  55. <param-value>pankaj</param-value>
  56. </context-param>
  57. <context-param>
  58. <param-name>DBPWD</param-name>
  59. <param-value>password</param-value>
  60. </context-param>
  61. <context-param>
  62. <param-name>DBURL</param-name>
  63. <param-value>jdbc:mysql://localhost/mysql_db</param-value>
  64. </context-param>
  65.  
  66. <listener>
  67. <listener-class>com.journaldev.listener.AppContextListener</listener-class>
  68. </listener>
  69.  
  70. public class AppContextListener implements ServletContextListener {
  71.  
  72. public void contextInitialized(ServletContextEvent servletContextEvent) {
  73. ServletContext ctx = servletContextEvent.getServletContext();
  74.  
  75. String url = ctx.getInitParameter("DBURL");
  76. String u = ctx.getInitParameter("DBUSER");
  77. String p = ctx.getInitParameter("DBPWD");
  78. }}
Add Comment
Please, Sign In to add comment