当前位置: 首页 > news >正文

javaee jstl表达式

jstl是el表达式的扩展

使用jstl需要添加jar包
在这里插入图片描述

package com.test.servlet;import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;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 com.test.pojo.Student;/*** Servlet implementation class TestJstlServlet*/
@WebServlet("/TestJstlServlet")
public class TestJstlServlet extends HttpServlet {private static final long serialVersionUID = 1L;/*** @see HttpServlet#HttpServlet()*/public TestJstlServlet() {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//response.getWriter().append("Served at: ").append(request.getContextPath());request.setAttribute("store_num", 50);request.setAttribute("price", 500);List<Student> list=new ArrayList<Student>();list.add(new Student(1,"daimenglaoshi","jisuanji","0101"));list.add(new Student(2,"daimenglaoshi2","yingyu","0101"));list.add(new Student(3,"zhangsan","jisuanji","0102"));request.setAttribute("student_list", list);Map<String, String> map=new HashMap<String,String>();map.put("name", "zhangsan");map.put("age","23");request.setAttribute("map",map);request.getRequestDispatcher("TestJstl.jsp").forward(request, response);}/*** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubdoGet(request, response);}}
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<c:if test="${store_num>10}">库存充足
</c:if><c:if test="${store_num<=10}">库存不足
</c:if><c:choose><c:when test="${price>1000}"> 太贵</c:when><c:when test="${price>500}"> 买得起</c:when><c:otherwise>太便宜了 不买了</c:otherwise>
</c:choose><c:forEach var="student" items="${student_list}" >${student.sname}<br/>
</c:forEach><c:forEach var="item" items="${map}">${item.key}  ${item.value}<br/></c:forEach></body>
</html>
package com.test.pojo;//琛ㄦ槧灏勭被
public class Student {private int sid;public int getSid() {return sid;}public void setSid(int sid) {this.sid = sid;}public String getSname() {return sname;}public void setSname(String sname) {this.sname = sname;}public String getMajor() {return major;}public void setMajor(String major) {this.major = major;}public String getStu_class() {return stu_class;}public void setStu_class(String stu_class) {this.stu_class = stu_class;}private String sname;private String major;private String stu_class;public Student(){}public Student(int sid,String sname,String major,String stu_class){this.sid=sid;this.sname=sname;this.major=major;this.stu_class=stu_class;}}
http://www.lryc.cn/news/94920.html

相关文章:

  • ChatGPT是否具有记忆能力?
  • ARP协议(地址分析协议)
  • c# websocket client java websocket server
  • 【玩转循环】探索Python中的无限可能性
  • 网安学习经历小记
  • MyBatis之慎用association
  • 【Java/大数据】Kafka简介
  • 【动手学深度学习】读写文件
  • http-server 的安装与使用
  • SQL高级教程
  • 9.pixi.js编写的塔防游戏(类似保卫萝卜)-群炮弹发射逻辑
  • 分布式链路追踪
  • 计算机网络————网络层
  • el-table刷新后保持高亮并改变状态字段
  • ARM Ubuntu内核更新记录
  • 【sgUploadTray】上传托盘自定义组件,可实时查看上传列表进度
  • 改进二进制粒子群算法在配电网重构中的应用(Matlab实现)【论文复现】
  • 【文章系列解读】Nerf
  • 基于springboot,vue网上订餐系统
  • Nautilus Chain 更换全新测试网,主网即将在不久上线
  • 攻防世界web:Web_php_wrong_nginx_config,python3后门
  • 【VUE】解决图片视频加载缓慢/首屏加载白屏的问题
  • spring复习:(35)在getBean时,在哪里根据普通bean和工厂bean进行区分处理来返回的?
  • Jenkins全栈体系(二)
  • c++11 标准模板(STL)(std::basic_istream)(九)
  • OpenSource - Spring Startup Ananlyzer
  • ES6迭代器、Set、Map集合和async异步函数
  • mac android studio设置跟mac系统一样的快捷键
  • Java-通过IP获取真实地址
  • Java代码实现word转PDF