在jsp文件中创建java函数并从另一个jsp文件中调用它 [英] create java function in a jsp file and call it from another jsp file

查看:149
本文介绍了在jsp文件中创建java函数并从另一个jsp文件中调用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们通常在java类中创建方法,将它们导入jsp文件并在我们的jsp文件中调用这些方法。

We generally create methods in a java class, import them into a jsp file and call those methods in our jsp files.

但我们正在客户端环境中工作,我们无权创建或修改.java文件。所以我们迫切需要在jsp文件中创建一个函数并从另一个jsp文件中调用它。

But we are working in a client environment, we do not have access to create or modify .java files. So we desperately need to create a function in a jsp file and call it from another jsp file.

例如:

A.jsp

.....
<jsp:include page="B.jsp"/>
....
<%= getName(); %>

B.jsp ....

B.jsp ....

<%!
public String getName()
{
 return "Hello";
}
>%

有没有办法做到这一点?

Is there any way to do this?.

推荐答案

是的,你可以,而不是

<jsp:include page="B.jsp"/>

使用

<%@include file="B.jsp"%>

包含页面只会嵌入两个jsp代码,因此您没有获得该功能,但包含文件使用指令将首先嵌入代码然后编译,这样你就可以得到你的功能。

Including page will just embed two jsp code so you are not getting that function but including file using directives will embed code first and then compile so you will get your function.

你可以在这里找到差异

< jsp:include page = ..有什么区别。>和<%@ include file = ...>?

这篇关于在jsp文件中创建java函数并从另一个jsp文件中调用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆