How to add a separate web deployment descriptor?
-
28-09-2019 - |
Question
So i have a dynamic web project. Servlet mapping is defined in WEB-INF/web.xml
I know i can add further mapping in web.xml, but it get things easily messed up coz I am adding url paths that are just many.
So, how do i add a new web deployment descriptor that goes in hand with web.xml without messing the original configuration?
Solution
If you're using Tomcat 7, you can use the WebServlet
annotation. Like this:
@WebServlet(name="CalculatorServlet", urlPatterns={"/calc", "/getVal"})
public class CalculatorServlet extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res) {
...
}
...
}
This code is taken from http://java.sun.com/developer/technicalArticles/JavaEE/JavaEE6Overview_Part3.html.
If you're using Tomcat 6 or earlier, I think you're out of luck, since you'll have to declare all url paths in your web.xml
.
Perhaps you can use ant
or some other trickery to combine a relatively empty web.xml
with url paths defined somewhere else at build time.