Do I really need web.xml for a Servlet based Java web application? -
i haven't been working on real world web projects. @ university used both servlets , spring java web development. in both projects given web.xml files configured , doing minor changes in them. need build web app scratch. created new servlet class in eclipse , didn't automatically create web.xml. googled, , read several resources web.xml not needed, reasoning put in couple of sentences, not sure if using annotations instead of web.xml no problem. glad if there no need configure web.xml, because haven't configured 1 myself , want focus more on business logic.
thank in advance!
you don't need web.xml
file if have container supports latest j2ee specs. here link simple servlet example use annotation , here can find same spring mvc; post example here convenience
public class mywebapplicationinitializer implements webapplicationinitializer { @override public void onstartup(servletcontext container) { servletregistration.dynamic registration = container.addservlet("dispatcher", new dispatcherservlet()); registration.setloadonstartup(1); registration.addmapping("/example/*"); } }
here link show how use other annotations available(@servletfilter, @webservletcontextlistener); can download specs form here in order more detailed view of annotations available via j2ee.
Comments
Post a Comment