When we create a new Maven webapp project in NetBeans the JSP editing features are not enabled. If we open a JSP file we see the following error: Servlet API classes are not on the classpath, some scriplet editing features are disabled.
We need to add the Servlet API classes ourselves to the dependencies of our project. When the classes are in the classpath of our project we get complete code completion in our JSP editor. So how do we add the API classes? First we go to Window | Other | | Maven Repository Browser. We click on the Find icon on the right to search for the Servlet API. In the search dialog window we type
javax.servlet and press the OK button:
NetBeans shows the search results in the Maven Repository Browser:
We need at least javax.servlet:servlet-api. We open this node and select versions 2.5[jar]. We right-click with the mouse and select Add Dependency to:
NetBeans opens a dialog window where we select our Maven webapp project and click the Add button.
This is enough to get some code completion in the JSP editor. To also get support for EL expressions we add the following libraries: javax.servlet.jsp:jsp-api and javax.servlet:jstl. Now when we return to our JSP editor we see how we can use code completion:
Finally to we can edit our
pom.xml and set the scope of the added libaries to
provided, because the application server we deploy the application to will already have these classes in the classpath.