<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>在线电影列表 - 观看最新热门电影</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
    <div class="container">
        <h1 class="text-center mt-5">最新电影</h1>
        <table class="table table-striped mt-3">
            <thead>
                <tr>
                    <th>影片编号</th>
                    <th>影片名称</th>
                    <th>影片时长</th>
                    <th>影片类型</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <c:forEach items="${filmList}" var="f">
                    <tr>
                        <td>${f.fid}</td>
                        <td>${f.fname}</td>
                        <td>${f.fduration}</td>
                        <td>${f.ftags}</td>
                        <td><a href="#" class="btn btn-primary">定票</a></td>
                    </tr>
                </c:forEach>
            </tbody>
        </table>
    </div>
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>
<p>package servlet;</p>
<p>import model.Film;
import service.impl.QueryAllFilmServiceImpl;
import util.JdbcUtil;</p>
<p>import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;</p>
<p>/**</p>
<ul>
<li>@author 高蒙蒙</li>
<li>@date 2023/8/15 12:25
*/
@WebServlet(&quot;/FilmServlet&quot;)
public class FilmServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
List<Film> filmList = new QueryAllFilmServiceImpl().queryAllFilm();
req.setAttribute(&quot;filmList&quot;, filmList);
req.getRequestDispatcher(&quot;/index.jsp&quot;).forward(req, resp);
}
}
filmList被正确设置为请求属性。
引入了JSTL标签库
index.jsp页面接收不到显示名为&quot;filmList&quot;的请求属性
中文解释原因内容:可能的原因是在servlet中设置了请求属性&quot;filmList&quot;,但是在index.jsp页面中无法接收到该请求属性。这可能是由于以下几个原因导致的:</li>
</ul>
<ol>
<li>未正确导入JSTL标签库:在index.jsp页面的开头,需要导入JSTL标签库的标签,以便正确使用JSTL表达式。请确保已经正确导入了JSTL标签库,例如使用了以下标签库导入语句:</li>
</ol>
<pre><code class="language-jsp">&lt;%@ taglib prefix=&quot;c&quot; uri=&quot;http://java.sun.com/jsp/jstl/core&quot; %&gt;
</code></pre>
<ol start="2">
<li>未正确设置contentType:在index.jsp页面的开头,需要设置正确的contentType。请确保已经设置contentType为&quot;text/html;charset=UTF-8&quot;,以确保页面能够正确显示中文字符集。例如使用了以下语句:</li>
</ol>
<pre><code class="language-jsp">&lt;%@ page contentType=&quot;text/html;charset=UTF-8&quot; language=&quot;java&quot; %&gt;
</code></pre>
<ol start="3">
<li>servlet转发路径错误:在FilmServlet中,使用<code>req.getRequestDispatcher(&quot;/index.jsp&quot;)</code>进行转发,确保转发路径正确并且index.jsp页面位于正确的位置。请检查index.jsp页面是否在正确的位置,并且路径是否正确。</li>
</ol>
<p>如果以上步骤都正确,但仍然无法接收到请求属性&quot;filmList&quot;,可能是由于其他原因,例如在servlet中未正确设置请求属性或者在index.jsp页面中未正确使用JSTL表达式。请仔细检查代码,确保没有其他错误。</p>
在线电影列表 - 观看最新热门电影

原文地址: https://www.cveoy.top/t/topic/qk0h 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录