心好累,学到这里完全跟不上了,不知道老师是怎么操作出来的?
我敲完代码,运行啥也没有?
完全懵,很晕。不知道自己是谁,在干嘛,为啥啥也没有?
<?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() { } }
是哪里出错了吗?也没看到报错啥的啊?咋就啥也没有呢?这叫我怎么弄?
0
收起
正在回答 回答被采纳积分+1
3回答
从网页搭建入门Java Web2018版
- 参与学习 人
- 提交作业 1088 份
- 解答问题 10205 个
如果你有Java语言基础,又想以后从事Java Web开发,那么本路径是你的不二选择!本路径从网页搭建开始入手,通过大量案例来学习Java Web基础。定能助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星