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();
}