I'm having an issue in web.xml file.
I'm getting the error, 'Server Tomcat v8.0 Server at localhost failed to start.' when I try to run my application. But this error can be bypassed when tag is used to web.xml file as shown below.
But the new issue is, when I context parameters are used in web.xml , they cannot be used from the listener class.
ServletContext sc=event.getServletContext();
String database= sc.getInitParameter("Database");
The database value always recieved as null. When element tags and tags are removed database string extracts the correct value. But tag needs servlet tags to be worked.
Can someone tell me a solution for this. Here below I have given the web.xml file
<?xml version="1.0" encoding="UTF-8"?>
<element>
<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" version="3.0">
<display-name>A</display-name>
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>com.manage.control.EnrollmentServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/EnrollmentServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<listener>
<listener-class>com.test.listener.DeatabaseNameListener</listener-class>
</listener>
<context-param>
<param-name>Database</param-name>
<param-value>jdbc:mysql://localhost:3307/studentmanagement</param-value>
</context-param>
<context-param>
<param-name>DatabaseUserName</param-name>
<param-value>root</param-value>
</context-param>
<context-param>
<param-name>DatabasePassword</param-name>
<param-value>root</param-value>
</context-param>
</web-app>
</element>