当前位置:  开发笔记 > 编程语言 > 正文

forEach标签有问题

如何解决《forEach标签有问题》经验,为你挑选了1个好方法。

嗨所有我在使用forEach进行迭代时遇到问题我给出完整的代码请告诉我这是错的.

的index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"  
  pageEncoding="ISO-8859-1"%>  
  
  
  
    
  Insert title here  
  
  
  
web.xml中

  
  FirstJsp  
    
    javax.faces.STATE_SAVING_METHOD  
    client  
      
    
    
    com.sun.faces.config.ConfigureListener  
    
    
    faces  
    javax.faces.webapp.FacesServlet  
    1  
    
    
    faces  
    *.jsf  
    
    
    faces  
    *.faces  
    

     
      
    foreachservlet  
    foreachservlet  
    com.foreach.foreachservlet  
    
    
    foreachservlet  
    /go  
    

    
    index.html  
    index.htm  
    index.jsp  
    default.html  
    default.htm  
    default.jsp  
    
    
    javax.servlet.jsp.jstl.fmt.localizationContext  
    resources.application  
    

Servlet代码:
package com.foreach;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class foreachservlet
 */
public class foreachservlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public foreachservlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub

        try{
            System.out.println("Getting inside get method--");
            String[] movieList={"Isquia","3 idiots","Kurbaan","Jab we met"};
            request.setAttribute("movieList",movieList);

            System.out.println("After setting attribute");
            RequestDispatcher dispatcher=request.getRequestDispatcher("/pages/welcome.jsp");
            dispatcher.forward(request, response);

                System.out.println("Last line--");

        }catch(Exception e){
            e.printStackTrace();
        }


    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

}
jsp代码:

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

Movie Collections


  Movie list

${movie}

我收到以下错误,我无法理解.

welcome.jsp:9:24: Static attribute must be a String literal, its illegal to specify an expression.

                       ^---^
welcome.jsp:9:24: Static attribute must be a String literal, its illegal to specify an expression.

                       ^---^

请帮忙.谢谢



1> skaffman..:

我认为这是因为taglib声明中的URI不正确.它应该是

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

代替

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

您正在使用的是旧的JSP-2.0之前的库,它不支持运行时表达式(表达式作为原始String传入并由标记本身而不是JSP引擎进行评估).

编辑:看起来这与JSP中的表达式语言无法正常工作相同

推荐阅读
oDavid_仔o_880
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有