2-12 自由编程
来源:2-12 自由编程
慕的地2082093
2020-01-17 21:30:03
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 dayServlet
*/
@WebServlet("/month")
public class monthServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public monthServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
Set<String> set=new HashSet<String>();
set.add("January");
set.add("February");
set.add("March");
set.add("April");
set.add("May");
request.setAttribute("month", set);
request.getRequestDispatcher("/month.jsp").forward(request, response);
//response.getWriter().append("Served at: ").append(request.getContextPath());
}
}
<%@ 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 ="${requestScope.month}" var="c" varStatus="idx">
<h1 style="font-weight:bold;">${idx.index+1}—${c}</h1>
</c:forEach>
</body>
</html>
老师,看下对吗?另外问下为什么使用style="font-weight:bold;"加粗字体没有效果?
1回答
好帮手慕柯南
2020-01-18
同学你好!
练习完成的不错。
关于你的疑惑:h标签默认就是加粗的,所以你再设置加粗的样式是无效的,你可以去掉加粗就可以看到效果了,比如:
如果我的回答解决了你的疑惑,请采纳,祝学习愉快~