I am new to Servlets and I will greatly appreciate if anyone could advise me on the problems I faced.
I am currently using eclipse IDE to write the servlet and I kept facing errors like:
"HTTP Status 404 - Servlet EasyQnServlet is not available" or sometimes "HTTP Status Report 500 Exception Report"
whenever I tried to pass some parameters to the servlet from my html page.
public class EasyQnServlet extends HttpServlet
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
// Set the response message's MIME type (in Content-Type response header)
// Get an output Writer to write the response message over the network
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN' 'http://www.w3.org/TR/html4/strict.dtd'>");
out.println("<body><h2>You have enter</h2>");
// Retrieve the value of the query parameters "title", "instructions
String title = request.getParameter("title");
String instructions = request.getParameter("instructions");
// Get null if the parameter is missing from query string.
// Get empty string or string of white spaces if user did not fill in
// Parameter: title
if (title == null || title.trim().equals(""))
Please enter the title.");
Title: " + title + "");
// Parameter: instructions
if (instructions == null || instructions.trim().equals(""))
Title: " + title + "");
I have kept my EasyQnServlet.java file in src>simuleqn and my html and web.xml file in webapps folder.
I can launch my html in eclipse (tomcat server), but when I clicked 'submit' after entering the inputs, I get HTTP Status (404 / 500) Error Report. I am not sure where the problem lies. Any help will be greatly appreciated!!
You mentioned about my EasyQnServlet class file? What do you mean by class file? Is it the same as my EasyQnServlet.java file which I put under src>simuleqn folder?
By the way, am I right to put my EasyQnServlet.java file in the src>simuleqn folder? (simuleqn is the package name).
Eclipse automatically put that java file under src (not WEB-INF folder) when I created that servlet.
I mean after compilation of EasyQnServlet.java file, EasyQnServlet.class file should reside inside WEB-INF\classes folder with proper package structure. Our web application has nothing to do with .java file so it doesn't matter where you are putting your .java file inside project. The only thing is that classes after compilation should reside inside WEB-INF\classes folder. Feel free to ask me if you have further queries regarding this.
Thank you so much for your reply. May I know what can I do to get the class file? You mentioned that class file is a file we get after we compiled the .java file. Does 'compile' means pressing the 'Run' button in the eclipse IDE? I have run the .java file (not servlet) many times when I wrote my mathematics java program.
I am sorry if my question is dumb. This is my first time using an IDE, and also writing a java program and servlet.
Thank you for your help once again.
java file is the source file you are coding...in your case it is a servlet file...it can be any java file in your application and must be put in the WEB-INF\classes directory under proper package structure...
when the application is deployed into ear or war.... all the java files in the WEB-INF\classes directory are compiled and converted to class files...and put into WEB-INF\classes in the proper directory structure....