archieve: homework5 if.jsp

This commit is contained in:
2025-04-21 13:26:58 +08:00
parent 4763732388
commit 3bed589aab
4 changed files with 79 additions and 0 deletions
@@ -0,0 +1,27 @@
package com.msksbr.homework5;
import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import java.io.IOException;
@WebServlet(name="MyServlet", urlPatterns="/MyServlet")
public class MyServlet extends HttpServlet {
public void doGet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) {
request.setAttribute("username", "msksbr");
request.setAttribute("password", "123456");
RequestDispatcher dispatcher=request.getRequestDispatcher("/my.jsp");
try {
dispatcher.forward(request, response);
} catch (ServletException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public void doPost(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) {
doGet(request, response);
}
}
+32
View File
@@ -0,0 +1,32 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<fieldset>
<c:if test="${param.action=='mon'}">
周一了:工作的第一天,加油!
</c:if>
<c:if test="${param.action=='tues'}">
周二了:工作的第二天,加油!
</c:if>
<c:if test="${param.action=='wed'}">
周三了:工作的第三天,加油!
</c:if>
<c:if test="${param.action=='thu'}">
周四了:工作的第四天,加油!
</c:if>
<c:if test="${param.action=='fri'}">
周五了:工作的第五天,加油!
</c:if>
<c:if test="${param.action=='sat'}">
周六了:休息的第一天!
</c:if>
<c:if test="${param.action=='sun'}">
周日了:休息的第二天!
</c:if>
</fieldset>
</body>
</html>