springboot整合jsp 遇到的问题

1,在idea中新建jsp文件

首先需要在springboot项目 在src 中webapp /WEB-INF/JSP

当我右键想新建一个jsp文件时默认没有

File->Project Struction ->modules 按加号 新增web,双击web resource directory 修改路径 web resource directory path为 当前项目目录/src/webapp ->WEB-INF->JSP

 

ok

创建jsp文件

2,jsp报错

Servlet.service() for servlet [jsp] threw exception
org.apache.jasper.JasperException: /WEB-INF/jsp/userList.jsp (line: [22], column: [4]) According to TLD or attribute directive in tag file, attribute [items] does not accept any expressions

本人jsp代码

 1 <%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="utf-8" %>
 2 <%@taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6     <title>Title</title>
 7 </head>
 8 <body>
 9 <table border="1" align="center" width="50%">
10     <tr>
11         <th>ID</th>
12         <th>name</th>
13         <th>age</th>
14     </tr>
15     <c:forEach items="${list}" var="user">
16         <tr>
17             <td>${user.id}</td>
18             <td>${user.name}</td>
19             <td>${user.age}</td>
20         </tr>
21     </c:forEach>
22 </table>
23 
24 </body>
25 </html>

maven依赖

<!-- JSP标准标签库(JSTL)是一个JSP标签集合,它封装了JSP应用的通用核心功能。 -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>

查看http://java.sun.com/jstl/core

jstl存在1.0和1.1的差异问题,用EL建议需要在1.1以上版本:

使用jstl1.1 

只要将u'serList.jsp文件中

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
换成:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

 或者也可以
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
改为
<%@ taglib uri=http://java.sun.com/jstl/core_rt prefix="c"%>

可能是因为使用了JSP2.0版本, 同时又没有使用JSTL core库的备用版本(RT库)

JSTL core库的有两种taglib伪指令, 其中RT库即是依赖于JSP传统的请求时属性值, 而不是依赖于EL来实现(称为EL库.JSP2.0将支持EL)

原文地址:https://www.cnblogs.com/brokencolor/p/10926116.html