JSP include page doesn't work

允我心安 提交于 2019-12-24 14:50:10

问题


I have a JSP file, member.jsp which is as follows :

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

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

and my html_functions.jsp is as follows :

<%!

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

%>

However, I get an exception while calling the member.jsp file. This is the exception I get :

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

Same is the case with all other methods. Where am I making the mistake ?

Thanks


回答1:


Using

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

works fine instead of <jsp:include page="html_functions.jsp" />

There are two ways of including a file in to the JSP page of your application. These are as follows:

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

first case includes the file or the text or the code of the file in the calling JSP file at compilation time and executes later.

See

and check html_functions.jsp is placed in correct path.



来源:https://stackoverflow.com/questions/12837714/jsp-include-page-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!