当前位置:网站首页>Servlet中数据传到JSP页面使用el表达式${}无法显示问题
Servlet中数据传到JSP页面使用el表达式${}无法显示问题
2022-07-03 02:04:00 【碳烤小肥羊。。。】
问题描述: el表达式${}标签的数据在页面没有显示。
首先看我的servlet和jsp页面。
Servlet代码:
@WebServlet(urlPatterns = "/demo1")
public class Servlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 1. 准备数据
List<Brand> brands = new ArrayList<>();
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("brands", brands);
// 3. 转发到 el-demo.jsp中
request.getRequestDispatcher("/el-demo.jsp").forward(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
}
JSP代码:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
${brands}
</body>
</html>
在浏览器中访问:http://localhost:8080/Jsp_demo/demo1,发现使用setAttribute封装在brands域中的数据并没有显示出来
原因:JSP和Servlet版本导致el功能默认关闭,加入<%@page isELIgnored="false"%>标签手动开启el功能。
修改后JSP代码:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false"%> <%-- 加入该标签手动开启el功能 --%>
<html>
<head>
<title>Title</title>
</head>
<body>
${brands}
</body>
</html>
再次在浏览器中访问:http://localhost:8080/Jsp_demo/demo1, el表达式${}可以正常显示了。
边栏推荐
- His experience in choosing a startup company or a big Internet company may give you some inspiration
- [Yu Yue education] reference materials of chemical experiment safety knowledge of University of science and technology of China
- How to find summer technical internship in junior year? Are you looking for a large company or a small company for technical internship?
- Everything file search tool
- 树形结构数据的处理
- Network security - Trojan horse
- Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance o
- easyExcel
- File class (check)
- 单词单词单词
猜你喜欢

詳細些介紹如何通過MQTT協議和華為雲物聯網進行通信

Hard core observation 547 large neural network may be beginning to become aware?

What are the key points often asked in the redis interview
![[leetcode] 797 and 1189 (basis of graph theory)](/img/2a/9c0a904151a17c2d23dea9ad04dbfe.jpg)
[leetcode] 797 and 1189 (basis of graph theory)

Processing of tree structure data

elastic stack

Y54. Chapter III kubernetes from introduction to mastery -- ingress (27)

What are MySQL locks and classifications

How to deal with cache hot key in redis

Recommendation letter of "listing situation" -- courage is the most valuable
随机推荐
[shutter] shutter debugging (debugging fallback function | debug method of viewing variables in debugging | console information)
LabVIEW安装第三方VISA软件后NI VISA失效
创建+注册 子应用_定义路由,全局路由与子路由
Learn BeanShell before you dare to say you know JMeter
可視化yolov5格式數據集(labelme json文件)
8 free, HD, copyright free video material download websites are recommended
Network security - DNS spoofing and phishing websites
Basic operation of view
Leetcode (540) -- a single element in an ordered array
[fluent] fluent debugging (debug debugging window | viewing mobile phone log information | setting normal breakpoints | setting expression breakpoints)
Internal connection query and external connection
Rockchip3399 start auto load driver
elastic stack
Leetcode(540)——有序数组中的单一元素
leetcode961. Find the elements repeated N times in the array with length 2n
Certaines fonctionnalités du développement d'applets
y54.第三章 Kubernetes从入门到精通 -- ingress(二七)
Redis:Redis的简单使用
MySQL learning 03
iptables 4层转发