当前位置:网站首页>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表达式${}可以正常显示了。
边栏推荐
- Exception handling in kotlin process
- String replace space
- Prohibited package name
- Su Shimin: 25 principles of work and life
- Network security - scanning and password explosion 2
- What are the differences between software testers with a monthly salary of 7K and 25K? Leaders look up to you when they master it
- es6 filter() 数组过滤方法总结
- Custom components, using NPM packages, global data sharing, subcontracting
- Leetcode (540) -- a single element in an ordered array
- udp接收队列以及多次初始化的测试
猜你喜欢
Coroutinecontext in kotlin
Stm32f407 ------- IIC communication protocol
Detailed introduction to the usage of Nacos configuration center
What are MySQL locks and classifications
Introduce in detail how to communicate with Huawei cloud IOT through mqtt protocol
小程序開發的部分功能
Certaines fonctionnalités du développement d'applets
PyTorch 卷积网络正则化 DropBlock
Technology sharing | Frida's powerful ability to realize hook functions
stm32F407-------DMA
随机推荐
[Yu Yue education] China Ocean University job search OMG reference
Network security - scan
Leetcode 183 Customers who never order (2022.07.02)
Network security - virus
详细些介绍如何通过MQTT协议和华为云物联网进行通信
When the epidemic comes, how to manage the team as a leader| Community essay solicitation
可視化yolov5格式數據集(labelme json文件)
返回一个树形结构数据
Network security OpenVAS
Detailed introduction to the deployment and usage of the Nacos registry
Cfdiv2 fixed point guessing- (interval answer two points)
[shutter] hero animation (hero realizes radial animation | hero component createrecttween setting)
What are the key points often asked in the redis interview
Exception handling in kotlin process
stm32F407-------DMA
全链路数字化转型下,零售企业如何打开第二增长曲线
Network security - DNS spoofing and phishing websites
[leetcode] 797 and 1189 (basis of graph theory)
[Yu Yue education] Jiujiang University material analysis and testing technology reference
Learn BeanShell before you dare to say you know JMeter