JSP从另一个jsp文件调用函数 [英] JSP calling a function from another jsp file

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

问题描述

嗨 我有一个JSP文件,尝试添加代码时遇到了64k限制错误. 所以我决定将代码添加到另一个jsp文件中,并将其包含在第一个文件中.

Hi i have a JSP file , while trying to add code i got the 64k limit error. so i decided to add the code to another jsp file and include it inside the first one.

first.jsp

first.jsp

.....
<jsp:include page="second.jsp"/>
....
<%= foo(); %>


second.jsp ....


second.jsp ....

<%!
public String foo()
{
 return "test";
}
>%


我尝试使用此命令,但出现以下错误消息: 对于类型first_jsp,未定义方法foo"


i try using this and i get this error message: "The method foo is undefined for the type first_jsp"

任何想法是什么问题,我该如何解决?

any idea what is the problem and how i can solve this ?

推荐答案

这是错误的方法.

首先,如果需要某种方法,请创建一个Java类,然后使用<%@ page import="your.package.YourClass*" %>

First, if you want some method, create a Java class, and import it using <%@ page import="your.package.YourClass*" %>

第二,根本不要在JSP页面中使用scriptlet.使用JSTL.可能是JSTL函数. 在此处查看

Second, don't use scriptlets in the JSP page at all. Use JSTL. Possibly JSTL functions. See here

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

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