【问题标题】:request.setAttribute("ob",ob) Expression language not working to display my obrequest.setAttribute("ob",ob) 表达式语言无法显示我的 ob
【发布时间】:2020-06-11 03:10:10
【问题描述】:

我使用了 test Var 并将其转发到我的 Jsp 页面,但是当我使用表达式语言显示它时不起作用。我的 bean 编码良好。一切正常。

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        FiliereDao filiereDb=new FiliereDao();
        String test="123";         // used to test
        request.setAttribute("listeFiliere",filiereDb.getFiliere());
        request.setAttribute("test",test);           


        this.getServletContext().getRequestDispatcher("/WEB-INF/admin.jsp").forward(request, response); 
    }

我的 jsp 部分不工作:我可以看到“hey z”显示,但我的 var 测试包含 123,我看不到它。

<c:forEach var="liste" items="${listeFiliere}">
            <li><c:out value="${ liste.idFiliere }" /> <c:out value="${ liste.nomFiliere }" /></li>
        </c:forEach>
 </ul>
<c:out value="${test}"/>      //expression language not working 
<c:out value="hey z"/>       // working 

我的 web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:jsp="http://java.sun.com/xml/ns/javaee/jsp" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>pfeKepler</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
   .
   .
   .
<jsp-config>
    <jsp-property-group>
      <url-pattern>*.jsp</url-pattern>
      <include-prelude>/WEB-INF/taglibs.jsp</include-prelude>
    </jsp-property-group>
  </jsp-config>
</web-app>

我的 jsp 配置:

<%@ page pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

我使用了测试变量,但也没有显示。

更新

我在 Eclipse 2019-09 中使用相同的配置 Tomcat v7.0 jstl1.2 测试了我的表达式语言,它运行良好。现在我正在使用 Eclipse Kepler,我无法切换到另一个。在此先感谢

UPDATE2.0

问题已解决,我在错误的 Servlet 中转发了我的 obj,这就是为什么我无法在我的 jsp Dummy 错误中获取它们。

【问题讨论】:

    标签: java eclipse eclipse-jee


    【解决方案1】:

    你可以改变

    <c:out value="${test}"/>
    

    <c:out value="${requestScope.test}"/>
    

    【讨论】:

      猜你喜欢
      • 2014-02-24
      • 2016-06-28
      • 2016-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多