心好累,学到这里完全跟不上了,不知道老师是怎么操作出来的?

心好累,学到这里完全跟不上了,不知道老师是怎么操作出来的?

我敲完代码,运行啥也没有?

http://img1.sycdn.imooc.com//climg/5cefead300014a6419201039.jpg

完全懵,很晕。不知道自己是谁,在干嘛,为啥啥也没有?

<?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_4_0.xsd"
         version="4.0">
    <filter>
        <filter-name>CharsetEncodingFilter</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>CharsetEncodingFilter</filter-name>
        <url-pattern>*.do</url-pattern>
    </filter-mapping>
    
    <servlet>
        <servlet-name>ProductServlet</servlet-name>
        <servlet-class>com.imooc.cart.data.ProductServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>ProductServlet</servlet-name>
        <url-pattern>/product/list.do</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>/index.jsp</welcome-file>
    </welcome-file-list>
</web-app>
package com.imooc.cart.servlet;

import com.imooc.cart.data.LocalCache;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 商品(课程)控制器
 */
public class ProductServlet extends HttpServlet {
    @Override
    public void init() throws ServletException {
        super.init();
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setAttribute("products", LocalCache.getProducts());
        req.getRequestDispatcher("/WEB-INF/views/biz/list.jsp");
    }

    @Override
    public void destroy() {
        super.destroy();
    }
}
package com.imooc.cart.data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 本地缓存
 */
public class LocalCache {
    private static Map<Long, Product> productMap = new HashMap<>();

    static{
        productMap.put(1l, new Product(1l,"HTML/CSS","HTML+CSS基础课程","HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义","初级",219));
        productMap.put(2l, new Product(2l,"HTML/CSS","HTML+CSS基础课程","HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义","初级",219));
        productMap.put(3l, new Product(3l,"HTML/CSS","HTML+CSS基础课程","HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义","初级",219));
        productMap.put(4l, new Product(4l,"HTML/CSS","HTML+CSS基础课程","HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义","初级",219));
        productMap.put(5l, new Product(5l,"HTML/CSS","HTML+CSS基础课程","HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义","初级",219));
        productMap.put(6l, new Product(6l,"HTML/CSS","HTML+CSS基础课程","HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义","初级",219));
        productMap.put(7l, new Product(7l,"HTML/CSS","HTML+CSS基础课程","HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义","初级",219));
        productMap.put(8l, new Product(8l,"HTML/CSS","HTML+CSS基础课程","HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义","初级",219));
        productMap.put(9l, new Product(9l,"HTML/CSS","HTML+CSS基础课程","HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义","初级",219));
        productMap.put(10l, new Product(10l,"HTML/CSS","HTML+CSS基础课程","HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义","初级",219));
    }

    public static List<Product> getProducts(){
        return new ArrayList<>(productMap.values());
    }
}
package com.imooc.cart.data;

/**
 * 商品(课程)
 */
public class Product {
    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;
    }

    private Long id;
    private String tag;//标签
    private String name;//名称
    private String desc;//描述
    private String level;//级别
    private int 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;
    }
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="./css/list.css">
</head>
<body>
<!-- 头部 -->
<header class="header">
    <div class="logo"></div>
    <div class="nav">
        <a href="" 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="" 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 class="course-content">
            <div class="course-nav-box">
                <span class="hd">方向 : </span>
                <div class="bd">
                    <ul>
                        <li class="course-nav-item active">
                            <a href="">全部</a>
                        </li>
                        <li class="course-nav-item">
                            <a href="">全部</a>
                        </li>
                        <li class="course-nav-item">
                            <a href="">全部</a>
                        </li>
                        <li class="course-nav-item">
                            <a href="">全部</a>
                        </li>
                        <li class="course-nav-item">
                            <a href="">全部</a>
                        </li>
                    </ul>
                </div>
            </div>
            <div class="course-nav-box">
                <span class="hd">方向 : </span>
                <div class="bd">
                    <ul>
                        <li class="course-nav-item active">
                            <a href="">全部</a>
                        </li>
                        <li class="course-nav-item">
                            <a href="">全部</a>
                        </li>
                        <li class="course-nav-item">
                            <a href="">全部</a>
                        </li>
                        <li class="course-nav-item">
                            <a href="">全部</a>
                        </li>
                        <li class="course-nav-item">
                            <a href="">全部</a>
                        </li>
                    </ul>
                </div>
            </div>
            <div class="course-nav-box">

                <span class="hd">方向 : </span>
                <div class="bd">
                    <ul>
                        <li class="course-nav-item active">
                            <a href="">全部</a>
                        </li>
                        <li class="course-nav-item">
                            <a href="">全部</a>
                        </li>
                        <li class="course-nav-item">
                            <a href="">全部</a>
                        </li>
                        <li class="course-nav-item">
                            <a href="">全部</a>
                        </li>
                        <li class="course-nav-item">
                            <a href="">全部</a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
    <div class="container">
        <!-- 课程列表 -->
        <div class="course-list">
            <div class="course-card-container">
                <a href="">
                    <div class="course-card">
                        <div class="course-card-top">
                            <span>HTML/CSS</span>
                        </div>
                        <div class="course-card-content">
                            <h3>HTML+CSS基础课程</h3>
                            <p>HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义</p>
                            <div class="course-card-bottom">
                                <span>初级 ~ 111111</span>
                                <span></span>
                            </div>
                        </div>
                    </div>
                    <div class="course-card-bk">
                        <img src="./img/bk1.jpg" alt="">
                    </div>
                </a>
            </div>
            <div class="course-card-container">
                <a href="">
                    <div class="course-card">
                        <div class="course-card-top">
                            <span>HTML/CSS</span>
                        </div>
                        <div class="course-card-content">
                            <h3>HTML+CSS基础课程</h3>
                            <p>HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义</p>
                            <div class="course-card-bottom">
                                <span>初级 ~ 111111</span>
                                <span></span>
                            </div>
                        </div>
                    </div>
                    <div class="course-card-bk">
                        <img src="./img/bk1.jpg" alt="">
                    </div>
                </a>
            </div>
            <div class="course-card-container">
                <a href="">
                    <div class="course-card">
                        <div class="course-card-top">
                            <span>HTML/CSS</span>
                        </div>
                        <div class="course-card-content">
                            <h3>HTML+CSS基础课程</h3>
                            <p>HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义</p>
                            <div class="course-card-bottom">
                                <span>初级 ~ 111111</span>
                                <span></span>
                            </div>
                        </div>
                    </div>
                    <div class="course-card-bk">
                        <img src="./img/bk1.jpg" alt="">
                    </div>
                </a>
            </div>
            <div class="course-card-container">
                <a href="">
                    <div class="course-card">
                        <div class="course-card-top">
                            <span>HTML/CSS</span>
                        </div>
                        <div class="course-card-content">
                            <h3>HTML+CSS基础课程</h3>
                            <p>HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义</p>
                            <div class="course-card-bottom">
                                <span>初级 ~ 111111</span>
                                <span></span>
                            </div>
                        </div>
                    </div>
                    <div class="course-card-bk">
                        <img src="./img/bk1.jpg" alt="">
                    </div>
                </a>
            </div>
            <div class="course-card-container">
                <a href="">
                    <div class="course-card">
                        <div class="course-card-top">
                            <span>HTML/CSS</span>
                        </div>
                        <div class="course-card-content">
                            <h3>HTML+CSS基础课程</h3>
                            <p>HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义</p>
                            <div class="course-card-bottom">
                                <span>初级 ~ 111111</span>
                                <span></span>
                            </div>
                        </div>
                    </div>
                    <div class="course-card-bk">
                        <img src="./img/bk1.jpg" alt="">
                    </div>
                </a>
            </div>
            <div class="course-card-container">
                <a href="">
                    <div class="course-card">
                        <div class="course-card-top">
                            <span>HTML/CSS</span>
                        </div>
                        <div class="course-card-content">
                            <h3>HTML+CSS基础课程</h3>
                            <p>HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义</p>
                            <div class="course-card-bottom">
                                <span>初级 ~ 111111</span>
                                <span></span>
                            </div>
                        </div>
                    </div>
                    <div class="course-card-bk">
                        <img src="./img/bk1.jpg" alt="">
                    </div>
                </a>
            </div>
            <div class="course-card-container">
                <a href="">
                    <div class="course-card">
                        <div class="course-card-top">
                            <span>HTML/CSS</span>
                        </div>
                        <div class="course-card-content">
                            <h3>HTML+CSS基础课程</h3>
                            <p>HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义</p>
                            <div class="course-card-bottom">
                                <span>初级 ~ 111111</span>
                                <span></span>
                            </div>
                        </div>
                    </div>
                    <div class="course-card-bk">
                        <img src="./img/bk1.jpg" alt="">
                    </div>
                </a>
            </div>
            <div class="course-card-container">
                <a href="">
                    <div class="course-card">
                        <div class="course-card-top">
                            <span>HTML/CSS</span>
                        </div>
                        <div class="course-card-content">
                            <h3>HTML+CSS基础课程</h3>
                            <p>HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义</p>
                            <div class="course-card-bottom">
                                <span>初级 ~ 111111</span>
                                <span></span>
                            </div>
                        </div>
                    </div>
                    <div class="course-card-bk">
                        <img src="./img/bk1.jpg" alt="">
                    </div>
                </a>
            </div>
            <div class="course-card-container">
                <a href="">
                    <div class="course-card">
                        <div class="course-card-top">
                            <span>HTML/CSS</span>
                        </div>
                        <div class="course-card-content">
                            <h3>HTML+CSS基础课程</h3>
                            <p>HTML+CSS基础教程8小时带领大家步步深入学习标签用法和意义</p>
                            <div class="course-card-bottom">
                                <span>初级 ~ 111111</span>
                                <span></span>
                            </div>
                        </div>
                    </div>
                    <div class="course-card-bk">
                        <img src="./img/bk1.jpg" alt="">
                    </div>
                </a>
            </div>
        </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>
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 doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        servletRequest.setCharacterEncoding(encoding);
        filterChain.doFilter(servletRequest, servletResponse);
    }

    @Override
    public void destroy() {

    }
}

是哪里出错了吗?也没看到报错啥的啊?咋就啥也没有呢?这叫我怎么弄?

http://img1.sycdn.imooc.com//climg/5cefeb510001e04513371021.jpg

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

3回答
提问者 讓倪飛翔 2019-05-31 17:20:51

http://img1.sycdn.imooc.com//climg/5cf0f1980001c87112551029.jpg

为啥视频里老师一运行就OK了,我每次都这么多坎坷。而且重点是,我不知道该怎么办,这是最恐怖的,只能干瞪眼,不知道这是什么,说明了什么,问题可能出自哪里,我该做什么?

  • 同学可以将你上次截图里有的,catalina Log 中标红的部分复制粘贴出来。
    2019-05-31 17:59:20
芝芝兰兰 2019-05-31 13:57:20

同学你好。request.getRequestDispatcher(" ")需要调用forword才能完成转发,同学的代码只是获取了RequestDispatcher对象,没有转发而是停在了Servlet中,所以是白屏哦

http://img1.sycdn.imooc.com//climg/5cf0c1df0001e53c07420156.jpg

如果解答了同学的疑问,望采纳~

祝学习愉快~


  • 提问者 讓倪飛翔 #1
    加上forward。错误从500变成404了。还需要我做什么吗?
    2019-05-31 17:19:15
提问者 讓倪飛翔 2019-05-30 22:42:06

http://img1.sycdn.imooc.com//climg/5cefebb00001fc1819201039.jpg

真的也不知道里面说了个啥?反正就是啥也没有出来

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
从网页搭建入门Java Web2018版
  • 参与学习           人
  • 提交作业       1088    份
  • 解答问题       10205    个

如果你有Java语言基础,又想以后从事Java Web开发,那么本路径是你的不二选择!本路径从网页搭建开始入手,通过大量案例来学习Java Web基础。定能助你完成Java Web小白的蜕变!

了解课程
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师