JSP包含页面不起作用

时间:2012-10-11 10:40:47

标签: jsp java-ee scriptlet

我有一个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

所有其他方法的情况也是如此。我在哪里弄错了?

由于

1 个答案:

答案 0 :(得分:4)

使用

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

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

将文件包含在应用程序的JSP页面中有两种方法。具体如下:

  1. <%@include file="relativeURL" %>
  2. <jsp:include page="relativeURL" />
  3. 第一种情况包括编译时调用JSP文件中文件或文本或文件代码,稍后执行。

    See

    并检查html_functions.jsp是否放置在正确的路径中。