表达式为jsp:include

时间:2016-03-10 21:23:07

标签: java jsp

有没有办法在JSP中做这样的事情:

<% String path = session.getAttribute("path").toString(); %>
<jsp:include page="<%=path%>/vue/includes/header.jsp"/>
path中的

localhost:8080

谢谢,

我有一个错误: attribute for %>" is not properly terminated

以下是代码:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<jsp:useBean id="User" class="metier.User"/>
<jsp:useBean id="Pays" class="metier.Pays"/>
<jsp:setProperty name="User" property="login" param="login"/>
<jsp:setProperty name="User" property="pass" param="pass"/>
<% String path = session.getAttribute("path").toString(); %>
<!DOCTYPE html>
<html>
   <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <jsp:include page="<%=path%>/vue/includes/header.jsp"/>
        <h1>Hello</h1>
        <c:forEach var="p" items="${Pays.getPays()}"> 
            <a href="<%=path%>/vue/team.jsp?idPays=${p.idPays}"><c:out value="${p.name}"/></a><br/>
        </c:forEach>
        <jsp:include page="<%=path%>/vue/includes/footer.jsp"/>
    </body>
</html>

header.jsp只是一个HTML文件

PS:我是JSP的初学者

1 个答案:

答案 0 :(得分:0)

这应该有效

<% String path = session.getAttribute("path").toString();
   String url = "http://" + path + "/vue/includes/header.jsp";
%>
<c:import url='${url}'/>