出现500错误
来源:2-13 自由编程
Adopat
2019-07-17 00:01:50
package com.imooc.jstl.practice; public class Notice { private String id; private String name; public Notice(String id,String name) { this.id=id; this.name=name; } public String getcid() { return id; } public void setcid(String cid) { this.id = cid; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String toString() { return id+"-----"+name; } } package com.imooc.jstl.practice; 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("001","欢迎来到慕课网!")); list.add(new Notice("002","欢迎学习Java Web课程!")); list.add(new Notice("003","一定要多写代码,多练习哟!")); request.setAttribute("notice", list); request.getRequestDispatcher("/notice.jsp").forward(request, response); } } <%@ 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> <h1>公告展示</h1> <c:forEach items="${requestScope.notice}" var="notice" varStatus="idx"> <h2>${idx.index}.${notice.id}---${notice.name}</h2> </c:forEach> </body> </html>
1回答
同学你好,同学的Notice类中id属性的get和set方法有些问题,属性的get和set方法的方法名应该是get/set加上属性名,属性名首字母大写,如;
而同学写为了cid,如:
建议同学修改一下再试试。
如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~
相似问题