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:

    <title>TODO supply a title</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <form name = "managementReports" method = "get" action = 
    <input type="submit">

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  
PrintWriter pw = res.getWriter();

String name = req.getParameter("filename");

BufferedReader br = new BufferedReader(new 

String str;
while( (str = br.readLine()) != null )
 pw.println(str + "<BR>");


Here is my web.xml:

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"

Any suggestions would be appreciated

Recommended Answers

All 4 Replies

Member Avatar

Any suggestions would be appreciated

Post to the correct forum. This is the community forum. Doh!

I'm not sure if it's the root cause of your problem, but I don't think mixing xml based and annotation based configuration of your web application is a good idea.
I wouldn't be at all surprised if the servlet engine ignores the annotations if an xml based configuration is found.

I go with jwenting!!

XML based and annotation based configuration of your web application is not a good idea!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.