What is the purpose of javax.servlet.jsp-api

I’m learning how to make a compatible servlet 3.1 compatible webapp that will run on JBoss wildfly 10. I use maven for dependencies, and I'm not sure what the following dependencies do, and if they are enabled / disabled in the servlet container:

<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>${servlet.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>javax.servlet.jsp-api</artifactId> <version>2.3.1</version> </dependency> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>${jstl.version}</version> </dependency> 

I have already done several searches and would like to check or supplement the following information:

  • The api servlet is provided by the servlet container, so I can add <scope>provided</scope> to Maven. However, why should I include this jar? What classes or files will have errors when deleting?
  • I'm not sure what javax.servlet.jsp-api does. My peaceful example seems to work fine if I don't turn it on. What does it do? And do I need to add <scope>provided</scope> or not?
  • JSTL is not provided by any servlet container, so it must be explicitly added. This jar guarantees the correct processing of <c:xxx> and other major tags in my jsp.
+1
source share
1 answer

The dependency labeling, as indicated, will make it available for compilation time and testing class classes, but not for the path to the runtime - as you say, the container will provide the implementation of these APIs at runtime.

  • If you are developing a web application, it is unlikely that you can do without using classes from the servlet API (HttpServletRequest, HttpServletResponse, Filter, etc.). Although many frameworks distract most of the Servlet APIs, you will still probably need to work with this basic API.

  • Yes, add the provided area. However, you only need this in the compile-time path if, for example, you created a custom JSP tag by extending, say, javax.servlet.jsp.tagext.TagSupport (although the tag files provide a more modern way to create custom tags).

  • Yes and yes.

+1
source

Source: https://habr.com/ru/post/1488288/


All Articles