通过jsp与el对数据进行查询(引入jstl) | 您所在的位置:网站首页 › jsp中引入java › 通过jsp与el对数据进行查询(引入jstl) |
通过jsp与el对数据进行查询 package com.mab.sevelet;import com.mab.dao.EmpDao;import com.mab.dao.impl.EmpDaoImpl;import com.mab.pojo.Emp;import javax.servlet.RequestDispatcher;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.List;@WebServlet("/httpServlet.do")public class servlet extends HttpServlet { //做一个对象empDao,去调用方法EmpDaoImpl() EmpDao empDao = new EmpDaoImpl(); @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { //对象empDao再调用具体方法findall();返回查询的数据给到findall,以数据队列的形式存储 List list = empDao.findall(); //把数据再发送到session中,页面缓存中 req.setAttribute("emps",list); //当收到的数据时,我们进行跳转到页面index.jsp进行展示 RequestDispatcher requestDispatcher = req.getRequestDispatcher("index.jsp"); //发送响应和请求 requestDispatcher.forward(req,resp); }} 优化JSP内容
排名 员工编号 员工姓名 员工职位 上级编号 入职日期 薪资 补贴 部门编号 薪资等级 ${emptStatus.count} ${empt.empno} ${empt.ename} ${empt.mgr} ${empt.job} ¥ ${empt.comm} ${empt.deptno} --%> A B C D E F G ${empt.sal le 1000 and empt.sal gt 500 ? "B":""} ${empt.sal le 1500 and empt.sal gt 1000 ? "C":""} ${empt.sal le 2000 and empt.sal gt 1500 ? "D":""} ${empt.sal le 3000 and empt.sal gt 2000 ? "E":""} ${empt.sal le 4000 and empt.sal gt 3000 ? "F":""} ${empt.sal gt 4000 ? "G":""}--%> Double sal = emp.getSal(); if(sal out.print("A"); }else if( sal out.print("B"); }else if( sal out.print("C"); }else if( sal out.print("D"); }else if( sal out.print("E"); }else if( sal out.print("F"); }else { out.print("G"); } %>--%> emps =(List) request.getAttribute("emps"); for (Emp emp : emps) { pageContext.setAttribute("empt",emp); %>--%> } %>--%>
|
CopyRight 2018-2019 实验室设备网 版权所有 |