0

我正在尝试检查文件是否存在,然后包含 JSP 文件,如果true. 但我从下面的代码中得到错误。

标记的语法错误,删除这些标记

file.handler 无法解析为类型

标记 "=", 的语法错误。预期的

这是我的代码:

String uri = request.getRequestURI();
String pageName = uri.substring(uri.lastIndexOf("/")+1);
String filename = pageName.replace(".jsp", "");

String path = request.getServletPath();  
path = path.replace( pageName , "");

String handler=path+"handler/"+filename+"_handler.jsp";

if(null != application.getResource(handler)){
    <%@include file="${handler}"%>
}

我是一名 PHP 程序员,但我是 JSP 新手。请指教

4

3 回答 3

1

您可以尝试使用调度程序来包含资源

if(null != application.getResource(handler)){
    request.getRequestDispatcher(handler).include(request, response);
}
于 2014-12-25T11:54:19.633 回答
0

尝试使用 JSP 表达式,例如:

<%@include file="<%=handler %>" %>
于 2014-12-25T11:05:04.313 回答
0

怎么样<jsp:include page="${handler}"/>

于 2014-12-25T11:10:56.663 回答