I am trying to create an HTML form which displays text from a text file, using a Java Servlet. I keep getting the following error: Error instantiating servlet class servlets.ReportServlet.
Here is the HTML page:
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form name = "managementReports" method = "get" action =
"ReportServlet">
<input type="submit">
</form>
</body>
</html>
And here is my servlet:
package servlets;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import javax.servlet.annotation.WebServlet;
@WebServlet(urlPatterns = { "/ReportServlet" })
public class ReportServlet extends HttpServlet
{
public void service(HttpServletRequest req, HttpServletResponse res) throws
ServletException, IOException
{
res.setContentType("text/html");
PrintWriter pw = res.getWriter();
String name = req.getParameter("filename");
BufferedReader br = new BufferedReader(new
FileReader("c:/Consignment.txt"));
String str;
while( (str = br.readLine()) != null )
{
pw.println(str + "<BR>");
}
br.close();
pw.close();
}
}
Here is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>CustomerServlet</servlet-name>
<servlet-class>servlet.CustomerServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>ConsignmentServlet</servlet-name>
<servlet-class>servlet.ConsignmentServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>ReportServlet</servlet-name>
<servlet-class>servlet.ReportServlet</servlet-class>
</servlet>
session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
I have been searching google for days but I am still struggling with this