请老师检查一下,谢谢!
来源:2-12 自由编程
MAYxDAY
2020-03-06 20:34:21
package com.imooc.jstl;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
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 Month
*/
@WebServlet("/Month")
public class Month extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Month() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Set<String> month=new HashSet();
month.add("May");
month.add("January");
month.add("February");
month.add("March");
month.add("April");
request.setAttribute("month", month);
request.getRequestDispatcher("/month.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>
<c:forEach items="${requestSpoce.month }" var="m" varStatus="idx">
<h2>${idx.index+1}-------${m}
</h2>
</c:forEach>
</body>
</html>
1回答
同学你好,代码编写的不错,但还有一点小问题,requestScope单词拼写错了,具体如下:
如果我的回答解决了你的疑惑,请采纳!祝学习愉快!
相似问题