1

I'm studying Head First Servlets and JSP and being stuck with this problem. The topic starts with page 480 of this book. I am trying to develop servlet without IDEs. This servlet should show list of films in a tabular form.

Here goes my code MoviesList.java:

package com.model;
import javax.servlet.*;
import javax.servlet.http.*;

public class MovieList extends HttpServlet{
    public void doGet(HttpServletRequest req, HttpServletResponse res){
        String[] movieList = {"Hannah Montana", "Kill Bill", "Terminator 2"};
        req.setAttribute("movieList", movieList);
    }
}

Show.jsp:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html><body>
<strong> Movie list:</strong>
<br><br>

<table>
     <c:forEach var="movie" items="${movieList}">
          <tr>
            <td>${movie}</td>
         </tr>
    </c:ForEach>    
</table>

</html></body>

Thing Tomcat8 shows in a browser:

type Exception report

Message: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application

Description: The server encountered an internal error that prevented it from fulfilling this request.

exception:

org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:55)
    org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:277)
    org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:75)
    org.apache.jasper.compiler.TagLibraryInfoImpl.generateTldResourcePath(TagLibraryInfoImpl.java:243)
    org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:124)
    org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:411)
    org.apache.jasper.compiler.Parser.parseDirective(Parser.java:469)
    org.apache.jasper.compiler.Parser.parseElements(Parser.java:1430)
    org.apache.jasper.compiler.Parser.parse(Parser.java:139)
    org.apache.jasper.compiler.ParserController.doParse(ParserController.java:227)
    org.apache.jasper.compiler.ParserController.parse(ParserController.java:100)
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:199)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:336)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:323)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:585)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:363)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

Note The full stack trace of the root cause is available in the Apache Tomcat/8.0.24 logs.

I cannot manage to bind code from my java class to jsp. Do I miss the DD or?

Now I solved it, thanks a lot!
I have got nex question:
It renders only text "Movie list:" and nothing more
How I fix that?

Now I changed my servlet code so it forwards request to Show.jsp and recompiled my class, rebooted tomcat but it still doesn't work...

req.setAttribute("movieList", movieList);


     try {

  getServletConfig().getServletContext().getRequestDispatcher(

    "Show.jsp").forward(req ,res );



} catch (ServletException e) {

  // TODO Auto-generated catch block

  e.printStackTrace();

} catch (IOException e) {

  // TODO Auto-generated catch block

  e.printStackTrace();

}
Vadixem
  • 99
  • 9

1 Answers1

2

By default Tomcat will not include JSTL library. So you should download the JSTL jars(standard.jar and jstl.jar) and put them in your application's WEB-INF/lib folder.

Govinda
  • 66
  • 2
  • I have added javax.servlet.jsp.jstl-1.2.1-javadoc to my WEB-INF/lib folder and now it shows: description The server encountered an internal error that prevented it from fulfilling this request. exception org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.Show_jsp org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:176) ....... Am I wrong with downloaded file? I got it on http://search.maven.org/#browse|-1002239620 – Vadixem Oct 26 '15 at 14:09
  • It seems I gained some progress. Just read [link](http://stackoverflow.com/tags/jstl/info) about JSTL thread and now it shows me next: /Show.jsp (line: 11, column: 1) The end tag "</c:ForEach" is unbalanced – Vadixem Oct 26 '15 at 14:15
  • Thank you so much! I solved this closing tag must be of lowerCase: ! It renders now "Movie list:" and nothing more...( Did I miss the scope or? – Vadixem Oct 26 '15 at 14:21