JSP包含页面不起作用 [英] JSP include page doesn't work
问题描述
我有一个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>;
返回结构;
} // formStart
public String printPageHeader(String name){
String structure =< li class = \listLi \> \ n< h3 class = \formHeader \> + name +。< / h3>< / li>;
返回结构;
} // printPageHeader
public String startMyLi(){
String structure =< li class = \listLi \>;
返回结构;
} // startMyLi
public String endLi(){
return(< / li>);
} // endMyLi
public String displayWithSpan(String str){
String structure =< span class = \labelSpan \> + str +< / span>;
返回结构;
} // displayWithSpan
public String displayInputElement(String name){
return(Hiiiii);
} // displayInputElement
%>
但是,我在调用member.jsp文件时遇到异常。这是我得到的例外:
org.apache.jasper.JasperException:无法为JSP编译类:
$的方法formStart(String)未定义p $ p>
jsp文件中的行:xx发生错误:/ member.jsp
类型add_005fmember_jsp
所有其他方法都是如此。我在哪里弄错了?
谢谢
解决方案使用
<%@ include file =/ html_functions.jsp%>
工作正常而不是
< jsp:include page =html_functions.jsp />
有两种方法可以将文件包含在应用程序的JSP页面中。具体如下:
<%@ include file =relativeURL%>
< jsp:include page =relativeURL/>
第一种情况包括编译时调用JSP文件中文件或文本或文件代码,稍后执行。
并检查html_functions.jsp是否放置在正确的路径中。
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
解决方案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:
<%@include file="relativeURL" %>
<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.
and check html_functions.jsp is placed in correct path.
这篇关于JSP包含页面不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!