JSP页面包括不工作(JSP include page doesn't work)

2019-10-17 07:48发布

我有一个JSP文件,member.jsp这是如下:

<%@ page import="java.util.*" %>
<jsp:include page="/html_functions.jsp" />

<% String heading = "Header" %>
<%= formStart("a_form") %>
<%= printPageHeader(heading) %>
<%= startMyLi() %>
<%= endLi() %>
<%= formEnd() %>

我html_functions.jsp如下:

<%!

public String formStart(String name) {
    String structure = "<div id=\"content\"><form name=\"" + name + "\" method=\"post\"><ul>";
    return structure;
}//formStart

public String printPageHeader(String name) {
    String structure = "<li class=\"listLi\">\n<h3 class=\"formHeader\">" + name + ".</h3></li>";
    return structure;
}//printPageHeader

public String startMyLi() {
    String structure = "<li class=\"listLi\">";
    return structure;
}//startMyLi

public String endLi() {
    return ("</li>");
}//endMyLi

public String displayWithSpan(String str) {
    String structure = "<span class=\"labelSpan\">" + str + "</span>";
    return structure;
}//displayWithSpan

public String displayInputElement(String name) {
    return("Hiiiii");
}//displayInputElement

%>

但是,我同时调用member.jsp文件得到一个异常。 这是例外,我得到:

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: xx in the jsp file: /member.jsp
The method formStart(String) is undefined for the type add_005fmember_jsp

同样是与所有其他方法的情况。 我在哪里做的错误?

谢谢

Answer 1:

运用

<%@ include file="/html_functions.jsp" %>

能正常工作,而不是<jsp:include page="html_functions.jsp" />

还有包括对应用程序的JSP页面文件的两种方式。 这些措施如下:

  1. <%@include file="relativeURL" %>
  2. <jsp:include page="relativeURL" />

第一种情况包括文件或文本或调用JSP文件中的文件在编译时的代码,后执行。

看到

检查html_functions.jsp被放置在正确的路径。



文章来源: JSP include page doesn't work