请老师帮忙看看哪里错了,运行就显示404错误
来源:2-13 自由编程
qq_咕噜咕噜_ceANR2
2019-05-08 12:30:12
Notice.java
package com.imooc.jstl;
public class Notice {
private String id;
private String name;
public Notice(String id,String name) {
this.id=id;
this.name=name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Notice [id=" + id + ", name=" + name + "]";
}
}
NoticeServlet.java
package com.imooc.jstl;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class NoticeServlet
*/
@WebServlet("/NoticeServlet")
public class NoticeServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public NoticeServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List list=new ArrayList();
list.add(new Notice("003","一定要多写代码,多练习哦"));
list.add(new Notice("002","欢迎学习Java Web课程"));
list.add(new Notice("001","欢迎来到慕课网"));
request.setAttribute("notice", list);
request.getRequestDispatcher("/notice.jsp").forward(request, response);
}
}
notice.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 var="n" items="${requestScope.notice }">
<h1>公告展示</h1>
<h2>${n.id }---${n.name }</h2>
</c:forEach>
</body>
</html>
1回答
好帮手慕柯南
2019-05-08
同学你好!代码没有任何问题呢,运行就是404是因为同学没有设置默认访问的页面,程序启动之后,同学直接在浏览器中输入要访问的地址就可以了,如果我的回答解决了你的疑惑,请采纳,祝学习愉快~