<%-- Created by IntelliJ IDEA. User: admin Date: 2023/6/29 Time: 16:29 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <title>Title</title> </head> <body> <%-- c:if :来完成逻辑判断,替换Java if else --%> <%-- <c:if test="true"> <h1>true</h1> </c:if> <c:if test="false"> <h1>false</h1> </c:if>--%> <c:if test="${status == 1}"> 启用 </c:if> <c:if test="${status == 0}"> 禁用 </c:if> </body> </html>
package com.itheima.web; import com.itheima.pojo.Brand; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.ArrayList; import java.util.List; @WebServlet("/Demo1") public class ServletDemo1 extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //1. 准备数据 List<Brand> brands = new ArrayList<Brand>(); brands.add(new Brand(1,"三只松鼠","三只松鼠",100,"三只松鼠,好吃不上火",1)); brands.add(new Brand(2,"优衣库","优衣库",200,"优衣库,服适人生",0)); brands.add(new Brand(3,"小米","小米科技有限公司",1000,"为发烧而生",1)); //2. 存储到request域中 request.setAttribute("brand",brands); request.setAttribute("status",1); //3. 转发到 el-demo.jsp // request.getRequestDispatcher("/el-demo.jsp").forward(request,response); request.getRequestDispatcher("/jst-if.jsp").forward(request,response); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request,response); } }
标签:request,response,JSTL,brands,import,servlet,javax From: https://www.cnblogs.com/Karl-hut/p/17514590.html