当前位置:网站首页>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表达式${}可以正常显示了。
边栏推荐
- 2022 financial product revenue ranking
- CFdiv2-Fixed Point Guessing-(区间答案二分)
- 微信小程序開發工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理問題
- The Sandbox阐释对元宇宙平台的愿景
- Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance o
- [shutter] bottom navigation bar implementation (bottomnavigationbar bottom navigation bar | bottomnavigationbaritem navigation bar entry | pageview)
- 【Camera专题】手把手撸一份驱动 到 点亮Camera
- 深度学习笔记(持续更新中。。。)
- The testing process that software testers should know
- Technology sharing | Frida's powerful ability to realize hook functions
猜你喜欢
Wechat applet development tool post net:: err_ PROXY_ CONNECTION_ Failed agent problem
8 free, HD, copyright free video material download websites are recommended
微信小程序开发工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理问题
Asian Games countdown! AI target detection helps host the Asian Games!
Custom components, using NPM packages, global data sharing, subcontracting
Visual yolov5 format data set (labelme JSON file)
Certaines fonctionnalités du développement d'applets
Detailed introduction to the deployment and usage of the Nacos registry
What are the key points often asked in the redis interview
技术大佬准备就绪,话题C位由你决定
随机推荐
Visual yolov5 format data set (labelme JSON file)
可視化yolov5格式數據集(labelme json文件)
What are the differences between software testers with a monthly salary of 7K and 25K? Leaders look up to you when they master it
2022 financial product revenue ranking
[leetcode] 797 and 1189 (basis of graph theory)
What are MySQL locks and classifications
创建+注册 子应用_定义路由,全局路由与子路由
stm32F407-------ADC
Answers to ten questions about automated testing software testers must see
Everything file search tool
Where is the future of test engineers? Confused to see
Network security - talking about security threats
Iptables layer 4 forwarding
微信小程序開發工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理問題
Summary of ES6 filter() array filtering methods
The technology boss is ready, and the topic of position C is up to you
Cfdiv2 fixed point guessing- (interval answer two points)
Network security OpenVAS
Deep learning notes (constantly updating...)
Recommendation letter of "listing situation" -- courage is the most valuable