0

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?

ivanceras
  • 1,415
  • 3
  • 17
  • 28

1 Answers1

4

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.

darioo
  • 46,442
  • 10
  • 75
  • 103
  • im using tomcat6, alright. this does mean i just have to really add it in at the bottom part of web.xml. thanks for a quick answer darioo – ivanceras Nov 25 '10 at 20:36