F
francan00
I have a JSP that outputs 10 links and it works great but want to cut
down on the scriptlet lines in my JSP.
Now I want to put the for loop that outputs the 10 links into a source
file and call the class in my JSP using just one line scriptlet.
Here is what my current JSP looks like where it outputs the 10 links:
<jsp:useBean id="pageinfo" class="storm.Pageinfo" scope="session" />
......
<%
if (pageinfo!=null)
{
for(int i=0;i < 10;i++)
{
out.println("<a href=moveto.jsp?inpage=" + i + ">" + i + "</
a>");
}
}
%>
Now my attempt to put it in a class outputs only 1 link instead of 10.
Source code for the Java class:
package storm;
import storm.*;
public class PageUtil
{
public static String theMethod(Pageinfo pageinfo)
{
if (pageinfo!=null)
{
for(int i=0;i < 10;i++)
{
return "<a href=moveto.jsp?inpage=" + i + ">" + i +
"</a>";
}
}
return "";
}
}
JSP scriptlet calling the static method:
<%= PageUtil.theMethod(pageinfo) %>
Please advise how I can get this to work. I am using Tomcat 4.1.27
and dont have JSTL.
down on the scriptlet lines in my JSP.
Now I want to put the for loop that outputs the 10 links into a source
file and call the class in my JSP using just one line scriptlet.
Here is what my current JSP looks like where it outputs the 10 links:
<jsp:useBean id="pageinfo" class="storm.Pageinfo" scope="session" />
......
<%
if (pageinfo!=null)
{
for(int i=0;i < 10;i++)
{
out.println("<a href=moveto.jsp?inpage=" + i + ">" + i + "</
a>");
}
}
%>
Now my attempt to put it in a class outputs only 1 link instead of 10.
Source code for the Java class:
package storm;
import storm.*;
public class PageUtil
{
public static String theMethod(Pageinfo pageinfo)
{
if (pageinfo!=null)
{
for(int i=0;i < 10;i++)
{
return "<a href=moveto.jsp?inpage=" + i + ">" + i +
"</a>";
}
}
return "";
}
}
JSP scriptlet calling the static method:
<%= PageUtil.theMethod(pageinfo) %>
Please advise how I can get this to work. I am using Tomcat 4.1.27
and dont have JSTL.