Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 嵌套EL函数_Java_Jsp_Jstl_El - Fatal编程技术网

Java 嵌套EL函数

Java 嵌套EL函数,java,jsp,jstl,el,Java,Jsp,Jstl,El,在JSP中执行此操作时,我遇到EL解析异常: <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt"%> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <%@page

在JSP中执行此操作时,我遇到EL解析异常:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@page import="my.InternalConstants"%>

[...]

<c:set var="MYPREFIX"><%=InternalConstants.MYPREFIX%></c:set>

[...]

<c:forEach var="name" items="${data.names}" varStatus="status">
    <c:set var="reducedName" value="${fn:substring(name, fn:length(MYPREFIX), fn:length(name))}"/> <-- here is where the exception occurs

我已经用下面的方法使用了你的代码。它工作得很好

JSP file

<%@page import="com.Utils"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<c:set var="MYPREFIX"><%=Utils.MYPREFIX%></c:set>
<c:forEach var="name" items="${names}" varStatus="status">
    <c:set var="reducedName"
        value="${fn:substring(name, fn:length(MYPREFIX), fn:length(name))}" />
        ${reducedName}
</c:forEach>



Controller File


@WebServlet("/HomeController")
public class HomeController extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public HomeController() {
        super();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        response.setContentType("text/html");

        List<String> list = new ArrayList<>();
        list.add("Ahasdasdadas");
        list.add("Ah1213232");

        request.setAttribute("names", list);
        RequestDispatcher rd = request.getRequestDispatcher("one.jsp");
        rd.forward(request, response);
    }

}

Utils

package com;

public class Utils {
    public static String MYPREFIX = "AH";
}
JSP文件
${reducedName}
控制器文件
@WebServlet(“/HomeController”)
公共类HomeController扩展HttpServlet{
私有静态最终长serialVersionUID=1L;
公共家庭控制器(){
超级();
}
受保护的void doGet(HttpServletRequest请求、HttpServletResponse响应)
抛出ServletException、IOException{
doPost(请求、响应);
}
受保护的void doPost(HttpServletRequest请求、HttpServletResponse响应)
抛出ServletException、IOException{
response.setContentType(“text/html”);
列表=新的ArrayList();
列表。添加(“AHASDAS”);
列表。添加(“Ah1213232”);
setAttribute(“名称”,列表);
RequestDispatcher rd=request.getRequestDispatcher(“one.jsp”);
转发(请求、响应);
}
}
乌提尔斯
包装组件;
公共类UTIL{
公共静态字符串MYPREFIX=“AH”;
}

如果您一直在使用WebSphere 8,那么您的问题似乎与之相关

看起来很好,只是在Tomcat 7.0.12上进行了测试,工作正常。你到底得到了什么例外?可能
${name}
根本不是
字符串。
JSP file

<%@page import="com.Utils"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<c:set var="MYPREFIX"><%=Utils.MYPREFIX%></c:set>
<c:forEach var="name" items="${names}" varStatus="status">
    <c:set var="reducedName"
        value="${fn:substring(name, fn:length(MYPREFIX), fn:length(name))}" />
        ${reducedName}
</c:forEach>



Controller File


@WebServlet("/HomeController")
public class HomeController extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public HomeController() {
        super();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        response.setContentType("text/html");

        List<String> list = new ArrayList<>();
        list.add("Ahasdasdadas");
        list.add("Ah1213232");

        request.setAttribute("names", list);
        RequestDispatcher rd = request.getRequestDispatcher("one.jsp");
        rd.forward(request, response);
    }

}

Utils

package com;

public class Utils {
    public static String MYPREFIX = "AH";
}