【问题标题】:JSP cannot resolve Servlet data object by using JSTL, IntelliJ IDEJSP 无法使用 JSTL、IntelliJ IDE 解析 Servlet 数据对象
【发布时间】: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>

有什么建议吗?我搜索了很多,但没有一个可以解决这个问题......

【问题讨论】:

  • 你可以试试 ,不过你的版本应该也可以。
  • 应该是&lt;c:forEach var="templist" items = "${requestScope.mystringlist}"&gt;
  • @dsp_user 我认为问题在于 .jsp 无法识别来自 servlet 的数据对象,所以这里的 ${templist} 基本上没有引用,对吧?我试过你的方法,不工作,没有显示:(
  • @MdZahidRaza 尝试过.. 不能以这种方式工作.. 我什至怀疑这是 jar 文件还是我的 ide 的错?但我更新了所有并交叉检查了 intellij 和 eclipse 两者,都一样..
  • 这似乎是环境问题,因为代码很好。

标签: jsp servlets intellij-idea


【解决方案1】:

我以其他方式遇到了这个问题,但我无法解决它。

我正在学习SpringMVC Hello world程序,并完成了复制代码(maven.pom..)然后我发现我无法获取EL数据。同时SpringMVC ModelAndView在setViewName()中有问题

我把鼠标放在这个功能上,命中是

没有找到视图解析器检查 Spring MVC 视图引用是否 正确解决。_来自 IntelliJ IDE

我想可能是一些 ModelAndView 映射错误,我不能让数据转到 JSP

我也用谷歌F12想看点东西,没找到:(

【讨论】:

    猜你喜欢
    • 2015-09-11
    • 2013-04-28
    • 2014-09-03
    • 2019-02-27
    • 1970-01-01
    • 2017-12-14
    • 1970-01-01
    • 2013-10-27
    • 2011-08-05
    相关资源
    最近更新 更多