请老师帮忙看看为什么我的jsp不显示body中的内容
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <filter> <filter-name>CharsetEncoding</filter-name> <filter-class>com.imooc.cart.filter.CharsetEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>CharsetEncoding</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>/index.jsp</welcome-file> </welcome-file-list> </web-app> <%-- Created by IntelliJ IDEA. User: Mr.Yao Date: 2019-04-17 Time: 17:35 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>CartDemo</title> <!-- 实现一进入到首页就进行跳转 refresh表示自由刷新 --> <meta http-equiv="refresh" content="0;url=<%= request.getContextPath()%>/product/list.do"> </head> </html> package com.imooc.cart.filter; import javax.servlet.*; import java.io.IOException; /** * 字符编码过滤器 */ public class CharsetEncodingFilter implements Filter { private String encoding; @Override public void init(FilterConfig filterConfig) throws ServletException { //从过滤器初始化获得编码格式 this.encoding = filterConfig.getInitParameter("encoding"); } @Override public void destroy() { } @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { servletRequest.setCharacterEncoding(encoding); filterChain.doFilter(servletRequest, servletResponse); } } package com.imooc.cart.data; /** * 商品(课程) */ public class Product { //课程编号 private Long id; //课程标签 private String tag; //课程名称 private String name; //课程描述 private String desc; //课程级别 private String level; //课程价格 精确到:元 private int price; public Product(Long id, String tag, String name, String desc, String level, int price) { this.id = id; this.tag = tag; this.name = name; this.desc = desc; this.level = level; this.price = price; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getTag() { return tag; } public void setTag(String tag) { this.tag = tag; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDesc() { return desc; } public void setDesc(String desc) { this.desc = desc; } public String getLevel() { return level; } public void setLevel(String level) { this.level = level; } public int getPrice() { return price; } public void setPrice(int price) { this.price = price; } } package com.imooc.cart.data; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 本地缓存 */ public class LocalCache { //创建Map,属性名是商品id,值是对应的商品 private static Map<Long,Product> map = new HashMap<>(); //采用静态代码块方式初始化商品 static { map.put(1l, new Product(1l, "HTML/CSS", "HTML+CSS基础课程", "HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义", "初级", 219)); map.put(2l, new Product(2l, "HTML/CSS", "HTML+CSS基础课程", "HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义", "初级", 219)); map.put(3l, new Product(3l, "HTML/CSS", "HTML+CSS基础课程", "HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义", "初级", 219)); map.put(4l, new Product(4l, "HTML/CSS", "HTML+CSS基础课程", "HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义", "初级", 219)); map.put(5l, new Product(5l, "HTML/CSS", "HTML+CSS基础课程", "HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义", "初级", 219)); map.put(6l, new Product(6l, "HTML/CSS", "HTML+CSS基础课程", "HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义", "初级", 219)); map.put(7l, new Product(7l, "HTML/CSS", "HTML+CSS基础课程", "HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义", "初级", 219));map.put(1l, new Product(1l, "HTML/CSS", "HTML+CSS基础课程", "HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义", "初级", 219)); map.put(8l, new Product(8l, "HTML/CSS", "HTML+CSS基础课程", "HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义", "初级", 219)); map.put(9l, new Product(9l, "HTML/CSS", "HTML+CSS基础课程", "HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义", "初级", 219)); map.put(10l, new Product(10l, "HTML/CSS", "HTML+CSS基础课程", "HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义", "初级", 219)); map.put(11l, new Product(11l, "HTML/CSS", "HTML+CSS基础课程", "HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义", "初级", 219)); map.put(12l, new Product(12l, "HTML/CSS", "HTML+CSS基础课程", "HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义", "初级", 219)); map.put(13l, new Product(13l, "HTML/CSS", "HTML+CSS基础课程", "HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义", "初级", 219)); map.put(14l, new Product(14l, "HTML/CSS", "HTML+CSS基础课程", "HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义", "初级", 219)); map.put(15l, new Product(15l, "HTML/CSS", "HTML+CSS基础课程", "HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义", "初级", 219)); map.put(16l, new Product(16l, "HTML/CSS", "HTML+CSS基础课程", "HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义", "初级", 219)); map.put(17l, new Product(17l, "HTML/CSS", "HTML+CSS基础课程", "HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义", "初级", 219)); map.put(18l, new Product(18l, "HTML/CSS", "HTML+CSS基础课程", "HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义", "初级", 219)); map.put(19l, new Product(19l, "HTML/CSS", "HTML+CSS基础课程", "HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义", "初级", 219)); map.put(20l, new Product(20l, "HTML/CSS", "HTML+CSS基础课程", "HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义", "初级", 219)); } /* 创建一个返回值为List的getProducts类 为了在getProducts中的修改不影响到商品初始化信息,可以实例化一个新的List对象,把value值放入 */ public static List<Product> getProducts() { return new ArrayList<>(map.values()); } } package com.imooc.cart.servlet; import com.imooc.cart.data.LocalCache; 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; @WebServlet("/product/list.do") public class ProductServlet extends HttpServlet { @Override public void init() throws ServletException { super.init(); } @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setAttribute("product", LocalCache.getProducts()); request.getRequestDispatcher("/WEB-INF/views/biz/list.jsp").forward(request, response); } @Override public void destroy() { super.destroy(); } } <%@page contentType="text/html; charset=UTF-8" language="java" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <html> <head> <meta charset="UTF-8"> <title>课程</title> <link rel="stylesheet" href="../../../css/list.css"> </head> <body> <!-- 头部 --> <header class="header"> <div class="logo"></div> <div class="nav"> <a href="/product/list.do" class="nav__item nav__course">课程</a> <a href="" class="nav__item nav__item_icon_new">职业路径<i class="icon_new"></i></a> <a href="" class="nav__item">实战</a> <a href="" class="nav__item">猿问</a> <a href="" class="nav__item">手记</a> </div> <div class="profile"> <a href="/cart/list.do" class="profile__item profile__car"></a> <a href="" class="profile__item profile__message"></a> <a href="" class="profile__item profile__ava"></a> </div> <div class="search"><input type="text" class="search_input"><a href="" class="search_submit"></a></div> </header> <div id="main"> <div class="wrap"> </div> <!-- 课程列表 --> <div class="course-list"> <c:forEach items="${products}" var="product"> <div class="course-card-container"> <div class="course-card"> <div class="course-card-top"> <span>${product.tag}</span> </div> <div class="course-card-content"> <%--<a href="/detail/detail.do?productId=${product.id}">--%> <h3>${product.name}-${product.id}</h3> <p>${product.desc}</p> </a> <div class="course-card-bottom"> <span>${product.level}</span> <span> <a href="/cart/cart.do?productId=${product.id}"> </a> </span> <a href="/favorite/favorite.do?productId=${product.id}"> <span></span> </a> </div> </div> </div> <div class="course-card-bk"> <img src="../../../img/bk1.jpg" alt=""> </div> </div> </c:forEach> </div> </div> <!-- 尾部 --> <footer class="footer"> <div class="waper"> <div class="footerWaper"> <div class="followus"> <a href="" class="followus_weixin"> <div class="flw-weixin-box"></div> </a> <a href="" class="followus_weibo"></a> <a href="" class="followus_qzone"></a> </div> <div class="footer_intro"> <div class="footer_link"> <ul> <li><a href="">网站首页</a></li> <li><a href="">企业合作</a></li> <li><a href="">人才招聘</a></li> <li><a href="">联系我们</a></li> <li><a href="">讲师招募</a></li> <li><a href="">常见问题</a></li> <li><a href="">意见反馈</a></li> <li><a href="">慕课大学</a></li> <li><a href="">友情链接</a></li> </ul> </div> <p>Copyright © 2017 imooc.com All Rights Reserved | 京ICP备 13046642号-2</p> </div> </div> </div> </footer> </body> </html>
我的css样式和img图片也都全部放入了,控制台也没有报错,jar包导入正常,以下是我的文件路径、各个包名以及运行显示的结果
尾部的footer也是能够正常显示的
3
收起
正在回答
7回答
你好!老师的代码里还有两个样式文件,你也放进去引入一下试试,因为我看到头部和尾部的样式是正常的,所以应该引入没问题。
祝学习愉快!
巴呆丶
2019-04-19 20:08:20
<%@page contentType="text/html; charset=UTF-8" language="java" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <html> <head> <meta charset="UTF-8"> <title>课程</title> <link rel="stylesheet" href="http://localhost:8080/css/list.css"> </head> <body> <!-- 头部 --> <header class="header"> <div class="logo"></div> <div class="nav"> <a href="/product/list.do" class="nav__item nav__course">课程</a> <a href="" class="nav__item nav__item_icon_new">职业路径<i class="icon_new"></i></a> <a href="" class="nav__item">实战</a> <a href="" class="nav__item">猿问</a> <a href="" class="nav__item">手记</a> </div> <div class="profile"> <a href="/cart/list.do" class="profile__item profile__car"></a> <a href="" class="profile__item profile__message"></a> <a href="" class="profile__item profile__ava"></a> </div> <div class="search"><input type="text" class="search_input"><a href="" class="search_submit"></a></div> </header> <div id="main"> <div class="wrap"> </div> <!-- 课程列表 --> <div class="container"> <div class="course-list"> <c:forEach items="${products}" var="product"> <div class="course-card-container" style="inline"> <div class="course-card"> <div class="course-card-top"> <span>${product.tag}</span> </div> <div class="course-card-content"> <a href="/detail/detail.do?productId=${product.id}"> <h3>${product.name}-${product.id}</h3> <p>${product.desc}</p> </a> <div class="course-card-bottom"> <span>${product.level}</span> <span> <a href="/cart/cart.do?productId=${product.id}"> </a> </span> <a href="/favorite/favorite.do?productId=${product.id}"> <span></span> </a> </div> </div> </div> <div class="course-card-bk"> <img src="../../../img/bk1.jpg" alt=""> </div> </div> </c:forEach> </div> </div> </div> <!-- 尾部 --> <footer class="footer"> <div class="waper"> <div class="footerWaper"> <div class="followus"> <a href="" class="followus_weixin"> <div class="flw-weixin-box"></div> </a> <a href="" class="followus_weibo"></a> <a href="" class="followus_qzone"></a> </div> <div class="footer_intro"> <div class="footer_link"> <ul> <li><a href="">网站首页</a></li> <li><a href="">企业合作</a></li> <li><a href="">人才招聘</a></li> <li><a href="">联系我们</a></li> <li><a href="">讲师招募</a></li> <li><a href="">常见问题</a></li> <li><a href="">意见反馈</a></li> <li><a href="">慕课大学</a></li> <li><a href="">友情链接</a></li> </ul> </div> <p>Copyright © 2017 imooc.com All Rights Reserved | 京ICP备 13046642号-2</p> </div> </div> </div> </footer> </body> </html>
说一下样式加载失败的原因吧,是因为缺少了<div class="container">这个标签导致样式加载失败
巴呆丶
2019-04-19 09:37:16
package com.imooc.cart.servlet; import com.imooc.cart.data.LocalCache; 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; @WebServlet("/product/list.do") public class ProductServlet extends HttpServlet { @Override public void init() throws ServletException { super.init(); } @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setAttribute("product", LocalCache.getProducts()); request.getRequestDispatcher("/WEB-INF/views/biz/list.jsp").forward(request, response); } @Override public void destroy() { super.destroy(); } }
相似问题
登录后可查看更多问答,登录/注册
从网页搭建入门Java Web2018版
- 参与学习 人
- 提交作业 1088 份
- 解答问题 10205 个
如果你有Java语言基础,又想以后从事Java Web开发,那么本路径是你的不二选择!本路径从网页搭建开始入手,通过大量案例来学习Java Web基础。定能助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星