我们通常在java类中创建方法,将它们导入jsp文件并在我们的jsp文件中调用这些方法.
但我们在客户端环境中工作,我们无权创建或修改.java文件.因此,我们迫切需要在jsp文件中创建一个函数,并从另一个jsp文件中调用它.
例如:
A.jsp
.....
<jsp:include page="B.jsp"/>
....
<%= getName(); %>
Run Code Online (Sandbox Code Playgroud)
B.jsp ....
<%!
public String getName()
{
return "Hello";
}
>%
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?
是的,你可以,而不是
<jsp:include page="B.jsp"/>
Run Code Online (Sandbox Code Playgroud)
使用
<%@include file="B.jsp"%>
Run Code Online (Sandbox Code Playgroud)
包含页面只会嵌入两个jsp代码,所以你没有获得该功能,但包含文件使用指令将首先嵌入代码然后编译,这样你就可以得到你的功能.
你可以在这里找到差异
<jsp:include page = ...>和<%@ include file = ...>之间有什么区别?
You should not create a function in Jsp file. JSP's are meant for view purpose only .
You can write the function in separate java class and call that class from whatever Jsp pages you want.
| 归档时间: |
|
| 查看次数: |
23514 次 |
| 最近记录: |