2-9 自由编程
来源:2-9 自由编程
慕的地2082093
2020-01-17 20:48:07
package com.imooc.jstl;
import java.io.IOException;
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("/day")
public class dayServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public dayServlet() {
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
request.setAttribute("day", "MONDAY");
request.getRequestDispatcher("/day.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>
<h1>${requestScope.day}</h1>
<c:choose>
<c:when test="${day == 'MONDAY' }">
<h2 style="color:blue">星期一</h2>
</c:when>
<c:when test="${day == 'TUESDAY' }">
<h2 style="color:blue">星期二</h2>
</c:when>
<c:when test="${day == 'WEDNESDAY' }">
<h2 style="color:blue">星期三</h2>
</c:when>
<c:when test="${day == 'THURSDAY' }">
<h2 style="color:blue">星期四</h2>
</c:when>
<c:when test="${day == 'FIRAY' }">
<h2 style="color:blue">星期五</h2>
</c:when>
<c:when test="${day == 'SATURDAY' }">
<h2 style="color:blue">星期六</h2>
</c:when>
<c:when test="${day == 'SUNDAY' }">
<h2 style="color:blue">星期日</h2>
</c:when>
<c:otherwise>
<h2 style="color:red">内容不对呦!</h2>
</c:otherwise>
</c:choose>
</body>
</html>
1回答
好帮手慕酷酷
2020-01-18
同学你好,代码完成的不错呦,继续努力!
如果我的回答解决了你的疑惑,请采纳!祝学习愉快!
相似问题