yossi
yossi

Reputation: 13325

JSP calling a function from another jsp file

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.

so i have

first.jsp

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

second.jsp ....

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

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 ?

Upvotes: 3

Views: 12124

Answers (2)

Bozho
Bozho

Reputation: 597402

This is the wrong way to do it.

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

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

Upvotes: 2

Bal
Bal

Reputation: 2087

Stop using scriptlets. Use JSTL tags to access your data and write your Java code in servlets/regular java classes.

Upvotes: 0

Related Questions