javax.servlet.jsp cannot be resolved to a type

jsp-ide-error

If your IDE produces an error like javax.servlet.jsp cannot be resolved to a type you shuold include the jsp-api dependency to solve that:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jsp-api</artifactId>
    <version>2.0</version>
    <scope>provided</scope>
</dependency>

Make sure that the scope is provided, because the servlet container that we use to run our project will provide this dependency. This is because the jsp-api is not required when compiling your project, it is only needed when you run the project (aka it is a runtime dependency).

For me, this error came up in STS (which is a variation of Eclipse), but you can expect it in other IDEs as well.

How to get the current context path in a JSP file

Most of the times when you want to place a link somewhere in you web application you want it to be relative to the context path (the root path under which your application is available).  This way, no matter where you navigate in your application, the link will always point to the same page.

In a JSP page you can use the following EL expression to get the context path:

${pageContext.request.contextPath}

For exmaple, if my context path is /jtuts and I want to set the action of a form to point to /jtuts/register then I would be able to do it the following way:

<form:form commandName="userForm" action="${pageContext.request.contextPath}/register" method="post">
    <!-- Contents skipped for brevity. -->
</form:form>