【发布时间】:2020-02-18 18:36:44
【问题描述】:
我现在正在学习基于 servlet 和 .jsp 的 MVC 基础知识; 但是当我尝试进行简单测试时,IntelliJ 给了我关于 items="${}" 的警告:“此检查报告可能的 EL 问题,例如未解决的引用和无效的 EL 位置”;
我在 web.xml 中检查了我的 servlet 配置;检查我的 .jsp 文件的路径是否在根目录中,但它不起作用;
这是我的代码:
--TestView.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>test view</title>
</head>
<body>
<c:forEach var="templist" items = "${mystringlist}">
${templist} <br/>
</c:forEach>
</body>
--TestServlet.java
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;
@WebServlet(name = "TestServlet")
public class TestServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String[] list = {"aaa","bbb","ccc","ddd","eee"};
request.setAttribute("mystringlist", list);
RequestDispatcher dispatcher = request.getRequestDispatcher("/TestView.jsp");
dispatcher.forward(request,response);
}
}
--web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>com.gpwz.labExcercise.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/TestServlet</url-pattern>
</servlet-mapping>
有什么建议吗?我搜索了很多,但没有一个可以解决这个问题......
【问题讨论】:
-
你可以试试
,不过你的版本应该也可以。 -
应该是
<c:forEach var="templist" items = "${requestScope.mystringlist}"> -
@dsp_user 我认为问题在于 .jsp 无法识别来自 servlet 的数据对象,所以这里的 ${templist} 基本上没有引用,对吧?我试过你的方法,不工作,没有显示:(
-
@MdZahidRaza 尝试过.. 不能以这种方式工作.. 我什至怀疑这是 jar 文件还是我的 ide 的错?但我更新了所有并交叉检查了 intellij 和 eclipse 两者,都一样..
-
这似乎是环境问题,因为代码很好。
标签: jsp servlets intellij-idea