0
votes
 $ java -version java version "1.6.0_45" Java(TM) SE Runtime
 Environment (build 1.6.0_45-b06-451-10M4406) Java HotSpot(TM) 64-Bit
 Server VM (build 20.45-b01-451, mixed mode)

Tomcat version: 7.0.40

I'm following the beginning servlet/jsp tutorial here:

https://stackoverflow.com/tags/servlets/info

and I am getting this error:

HTTP Status 500 - The absolute uri: http://java.sun.com/jsp/jstl/functions cannot be resolved in either web.xml or the jar files deployed with this application

Which looks like it's coming from the .jsp file which begins with this line:

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<!DOCTYPE html>
<html lang="en">

I compiled my servlet like this:

~/java_programs/modernServlet$ javac -cp /Library/Tomcat/lib/servlet-api.jar -d classes src/com/example/controller/HelloServlet.java

And then I copied that file to the same directory structure under WEB-INF classes in the Tomcat directory. Is there some other jar file I should be including in the classpath?

====

Okay, I downloaded and copied the jstl jar to Tomcat's lib directory, and and now I get all kinds of compile errors:

$ javac -cp "/Library/Tomcat/lib/servlet-api.jar;/Library/Tomcat/lib/jstl-1.2.jar" -d classes src/com/example/controller/HelloServlet.java
src/com/example/controller/HelloServlet.java:7: package javax.servlet does not exist
import javax.servlet.ServletException;
                    ^
src/com/example/controller/HelloServlet.java:8: package javax.servlet.annotation does not exist
import javax.servlet.annotation.WebServlet;
                               ^
src/com/example/controller/HelloServlet.java:9: package javax.servlet.http does not exist
import javax.servlet.http.HttpServlet;
                         ^
src/com/example/controller/HelloServlet.java:10: package javax.servlet.http does not exist
import javax.servlet.http.HttpServletRequest;
                         ^
src/com/example/controller/HelloServlet.java:11: package javax.servlet.http does not exist
import javax.servlet.http.HttpServletResponse;
                         ^
src/com/example/controller/HelloServlet.java:14: cannot find symbol
symbol: class HttpServlet
public class HelloServlet extends HttpServlet {
                                  ^
src/com/example/controller/HelloServlet.java:13: cannot find symbol
symbol: class WebServlet
@WebServlet("/hello")
 ^
src/com/example/controller/HelloServlet.java:17: cannot find symbol
symbol  : class HttpServletRequest
location: class com.example.controller.HelloServlet
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                         ^
src/com/example/controller/HelloServlet.java:17: cannot find symbol
symbol  : class HttpServletResponse
location: class com.example.controller.HelloServlet
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                                                     ^
src/com/example/controller/HelloServlet.java:17: cannot find symbol
symbol  : class ServletException
location: class com.example.controller.HelloServlet
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                                                                                          ^
src/com/example/controller/HelloServlet.java:23: cannot find symbol
symbol  : class HttpServletRequest
location: class com.example.controller.HelloServlet
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                          ^
src/com/example/controller/HelloServlet.java:23: cannot find symbol
symbol  : class HttpServletResponse
location: class com.example.controller.HelloServlet
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                                                      ^
src/com/example/controller/HelloServlet.java:23: cannot find symbol
symbol  : class ServletException
location: class com.example.controller.HelloServlet
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                                                                                           ^
src/com/example/controller/HelloServlet.java:16: method does not override or implement a method from a supertype
    @Override
    ^
src/com/example/controller/HelloServlet.java:22: method does not override or implement a method from a supertype
    @Override
    ^
15 errors
2
WTF? Why do we have an entire tutorial in the tag wiki? (Also the use of "post-process" and "preprocess" in that tag wiki is ... very strange). - Joachim Sauer
You may be missing the jstl jar from the classpath. - Lee Meador
@Lee Meador, Thanks for the response. I don't see a jstl jar in Tomcats lib directory. - 7stud
No need to add jstl library in classpath while compiling servlet. It should be placed inside your app. lib folder. - laksys
@laksys, App lib folder or Tomcat lib folder? If App lib folder, where in the directory structure does the lib folder go? - 7stud

2 Answers

1
votes

This is not a compilation error. This is a runtime error.

You just need to drop JSTL in /WEB-INF/lib as instructed in JSTL tag wiki page (and indirectly also the JSP tag wiki page).

You don't need to specify it in the compiletime classpath. It's namely a runtime error, not a compilation error. You successfully compiled the servlet, right?

Your compilation error while attempting to compile with JSTL in the classpath is caused because you're using Windows-specific path separator ; in the classpath while you're using an Unix based OS which expects : as path separator. But after all, you don't need JSTL in compiletime classpath.

0
votes

You will need to add the JSTL jar to the Tomcat lib folder.

You can download it by going here: http://mvnrepository.com/artifact/javax.servlet/jstl/1.2

Click the "download" button and just copy that file into Tomcat's lib folder.

New errors mean that servlet-api.jar is missing from the classpath.