Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在.jsp中的ArrayList上迭代(符合MVC2)_Java_Jsp_Servlets_Jstl_El - Fatal编程技术网

Java 在.jsp中的ArrayList上迭代(符合MVC2)

Java 在.jsp中的ArrayList上迭代(符合MVC2),java,jsp,servlets,jstl,el,Java,Jsp,Servlets,Jstl,El,我正在编写一个web应用程序,它使用servlet来维护视频数据对象的ArrayList(这些对象只包含有关电影的基本信息,如电影的标题、类型等) servlet将此列表放在请求的作用域中,并将请求和响应转发给jsp(此处仅显示servlet代码的一部分): 公共类VideoServlet扩展了HttpServlet{ 私有ArrayList库=新建ArrayList(); 公共无效数据集(HttpServletRequest请求, HttpServletResponse(响应){ 试一试{ /

我正在编写一个web应用程序,它使用servlet来维护视频数据对象的ArrayList(这些对象只包含有关电影的基本信息,如电影的标题、类型等)

servlet将此列表放在请求的作用域中,并将请求和响应转发给jsp(此处仅显示servlet代码的一部分):

公共类VideoServlet扩展了HttpServlet{
私有ArrayList库=新建ArrayList();
公共无效数据集(HttpServletRequest请求,
HttpServletResponse(响应){
试一试{
//将ArrayList置于请求的作用域中
setAttribute(“表”,库);
request.getRequestDispatcher(“/listvideos.jsp”).forward(请求,
反应);
...
listvideos.jsp如下所示。我收到一个Tomcat错误,指出JSTL的uri无法解析。我在jsp代码的其他部分中使用了EL,而不必像这样有任何特殊的导入行,我不确定JSTL是否仍然是解决这类问题的首选方法,同时仍然试图坚持MVC2和keeping Servlet中的所有Java代码。有人能给我指出正确的方向吗?如果可能的话,理想情况下我想要一个纯EL解决方案

<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 
'http://www.w3.org/TR/html4/loose.dtd'>

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

<html>

    <head>

        <title>Cattle Drive Assignment Servlets-4: Videos</title>

    </head>

    <body>

        <h1>Cattle Drive Assignment Servlets-4: Videos</h1>

        <form method='post' action='/videos/VideoServlet'>

            <a href="http://localhost:8080/videos/addvideo.jsp">Add a video</a>

            <br>
            <br>

            <table border="1">

                <tr>

                    <th>Title</th>

                    <th>Star</th>

                    <th>Type</th>

                    <th>VHS</th>

                    <th>DVD</th>

                    <th>Description</th>

                </tr>

                <c:forEach items="${the_table}" var="movie">

                <tr>

                    <td>${movie.getTitle()}</td>

                    <td>${movie.getStar()}</td>

                    <td>${movie.getType()}</td>

                    <td>${movie.inVHS()}</td>

                    <td>${movie.inDVD()}</td>

                    <td>${movie.getDesc()}</td>

                </tr>

                </c:forEach>

            </table>

        </form>

    </body>

</html>

牛路分配Servlets-4:视频
牛路分配Servlets-4:视频


标题 明星 类型 VHS 数字化视频光盘 描述 ${movie.getTitle()} ${movie.getStar()} ${movie.getType()} ${movie.inVHS()} ${movie.inDVD()} ${movie.getDesc()}
您的代码看起来基本正确。您看到的错误似乎表明在类路径中找不到JSTL标记库。请确保
JSTL.jar
standard.jar
在war的
WEB-INF/lib
文件夹中。

或者当您在Tomcat 6/7上时,单独使用JSTL-1.2.jar也足够了。另请参见
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 
'http://www.w3.org/TR/html4/loose.dtd'>

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

<html>

    <head>

        <title>Cattle Drive Assignment Servlets-4: Videos</title>

    </head>

    <body>

        <h1>Cattle Drive Assignment Servlets-4: Videos</h1>

        <form method='post' action='/videos/VideoServlet'>

            <a href="http://localhost:8080/videos/addvideo.jsp">Add a video</a>

            <br>
            <br>

            <table border="1">

                <tr>

                    <th>Title</th>

                    <th>Star</th>

                    <th>Type</th>

                    <th>VHS</th>

                    <th>DVD</th>

                    <th>Description</th>

                </tr>

                <c:forEach items="${the_table}" var="movie">

                <tr>

                    <td>${movie.getTitle()}</td>

                    <td>${movie.getStar()}</td>

                    <td>${movie.getType()}</td>

                    <td>${movie.inVHS()}</td>

                    <td>${movie.inDVD()}</td>

                    <td>${movie.getDesc()}</td>

                </tr>

                </c:forEach>

            </table>

        </form>

    </body>

</html>