老师 请帮忙看下代码哪里错了

来源:2-6 静态数据预加载

慕哥2028333

2020-02-08 20:45:34

错误信息:

http://img.mukewang.com/climg/5e3ead340956d66817120880.jpg



jsp代码:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
    <c:forEach items="${channllist} " var="c">
    <a href="${c.url}">${c.channelName }</a>
    </c:forEach>
    <hr>
</body>
</html>

监听器代码:

package com.imooc.listener;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import com.imooc.listener.entity.Channel;
@WebListener
public class StaticDatalistener implements ServletContextListener {

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        // TODO Auto-generated method stub
        List list = new ArrayList();
        list.add(new Channel("免费课程","http://localhost:8080/"));
        list.add(new Channel("实战课程","http://localhost:8080/"));
        list.add(new Channel("就业课程","http://localhost:8080/"));
        sce.getServletContext().setAttribute("channllist", list);
    }

}

初始信息代码:

package com.imooc.listener.entity;

public class Channel {
    private String channelName;
    private String url;
    public Channel(String channelName, String url) {
        super();
        this.channelName = channelName;
        this.url = url;
    }
    public String getChannelName() {
        return channelName;
    }
    public void setChannelName(String channelName) {
        this.channelName = channelName;
    }
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    public Channel() {
        super();
        // TODO Auto-generated constructor stub
    }
    
}


写回答

1回答

好帮手慕珊

2020-02-09

同学,你好!将如下箭头所指位置的空格去掉就可以了,这个位置不能有空格

http://img.mukewang.com/climg/5e3f6836096478e609220192.jpg

如果我的回答解决了你的疑惑,请采纳!祝学习愉快!

0

0 学习 · 9666 问题

查看课程