![]() In for example Tomcat, it's the /work directory. You can find the generated source code in the server's work directory. When a JSP is requested for the first time or when the web app starts up, the servlet container will compile it into a class extending HttpServlet and use it during the web app's lifetime. JSP also supports Expression Language, which can be used to access backend data (via attributes available in the page, request, session and application scopes), mostly in combination with taglibs. JSP supports taglibs, which are backed by pieces of Java code that let you control the page flow or output dynamically. JSP is a Java view technology running on the server machine which allows you to write template text in client side languages (like HTML, CSS, JavaScript, ect.). Same for a filter, listener, etc.Īnnotations don't have all these problems. Everything regarding a servlet is in the servlet class. No need to go to another file to add the mapping, then go back to the class because you forgot its exact name, then go back to the file again. You're creating a servlet, and you obviously want to map it to some URL. Or you rename a servlet class, but you forget to rename it in the web.xml as well, and you only discover the mistake at deployment time.įinally, they make our life easier. Using web.xml, you're forced to re-enter this class in web.xml: īut wait, you've made a typo and you'll only discover it at runtime. It avoids repeating yourself, and making mistakes by doing so. What is benefit of using java based config instead of web.xml for servlet 3.x? ![]() The minimum annotation should thus look like this rest of attributes are optional and thus not mandatory to get the servlet to function equally. The URL pattern /notifications/* will let the servlet listen on requests with extra path info as well. It does not kick in on requests with an extra path like /notifications/list or something. The URL pattern /notifications will let the servlet only listen on requests on exactly that path. įurther, there's a minor difference in the URL pattern. So, the root declaration of your web.xml must look like below (make sure you remove any DOCTYPE from web.xml too, otherwise it will still be interpreted as Servlet 2.3!). The support for servlet API annotations was only added in Servlet 3.0 (Tomcat 7). Otherwise Tomcat will still run in a fallback modus matching the Servlet version in web.xml. Provided that you're sure that you're using Tomcat 7 or newer, the webapp's web.xml has to be declared conform Servlet 3.0 spec in order to get Tomcat to scan and process the annotations.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |