0

My scenario of the operation is like this-->

I've a servlet code using Annotation :

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

import javax.servlet.annotation.WebServlet;


@WebServlet (name="MyAnnotationServlet", urlPatterns={"/hello"})


public class MyAnnotationServlet extends HttpServlet

{

public void service (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException

{

    res.setContentType ("text/html");

    PrintWriter out = res.getWriter();

    out.println ("<h2> Hello World </h2>");

    out.close();

}

}

Expected O/P : Hello World

I'm deploying the above servlet program in Tomcat container after making war file.

My first Question is: which files should I keep in the war file. Either only MyAnnotationServlet.class or only MyAnnotation.java or both.

and if the answer to first question is only MyAnnotationServlet.class then where should it be kept either under WEB-INF/classes or just open like this and not within any subfolder.

vrnvav97
  • 53
  • 5

1 Answers1

0

You don't need .java files which are before compilation(will be ignored), only compiled .class files

Usually classes should be under WEB-INF/classes

Notice that you better use packages other than default package , below the main classes folder

Ori Marko
  • 56,308
  • 23
  • 131
  • 233