Is there a way to do servlet mapping in the eclipse IDE other than manually?

Recently, I started developing servlets using Eclipse. Every time I write a servlet program, I need to manually match them in web.xml. Is there a way to automatically map servlets. Eclipse also asks for the URL template whenever I create a new servlet file. Why does he ask when it does not appear in web.xml on its own? Note: we also recommend using any useful plugin for servlet / jsp development ...

+5
source share
2 answers

Switch to Servlet 3.0 (Apache Tomcat 7.0, Glassfish 3, etc.), then you need to add @WebServletannotations to the servlet class.

@WebServlet("/foo")
public class FooServlet extends HttpServlet {
    // ...
}

What is it.

If you still adhere to Servlet 2.5 or later, you need to create the Servlet class as a Servlet class, and not as a Java class. In the Rightclick project, choose New> Servlet and complete the wizard. Thus, Eclipse will automatically generate the required display web.xml.

alt text

+10
source

If you want to use web.xml to map servlets, you need to select the dynamic version of web facet 2.5 instead of 3.0 in the dynamic web project

+6
source

All Articles