Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2007

Tip: Looking for answers? Try searching our database.

Put scriptlet lines in a class

Thread view: 
teser3@hotmail.com - 29 Aug 2007 16:49 GMT
I have this scriptlet working in a JSP and was wondering how I can put
it in a class file and call it in my JSP.

<jsp:useBean id="pageinfo" class="mypackage.PageInfo" scope="session"/

...
<%
if (pageinfo!=null) {
  if (pageinfo.isFirst()) {
      out.println("<a href=first.jsp>first</a>");
    }
}
%>

Would this be close because I am not sure how to create the method?

//in the class file
package mypackage;
import mypackage.pageinfo;

public String mymethod()
{
if (pageinfo!=null) {
  if (pageinfo.isFirst()) {
      out.println("<a href=first.jsp>first</a>");
    }
}
}

Then call it like this in JSP?

<% mymethod(); %>

I dont have JSTL or Struts on this Tomcat 4.1.27 container that I am
working on.
Daniel Pitts - 29 Aug 2007 18:50 GMT
On Aug 29, 8:49 am, "tes...@hotmail.com" <tes...@hotmail.com> wrote:
> I have this scriptlet working in a JSP and was wondering how I can put
> it in a class file and call it in my JSP.
[quoted text clipped - 32 lines]
> I dont have JSTL or Struts on this Tomcat 4.1.27 container that I am
> working on.

You'd have to pass a PageInfo object to "mymethod".  I would suggest
having mymethod return a string, rather than call out.println. that
way you can call it like:

<%= MyUtilsClass.mymethod(pageinfo) %>

public class MyUtilsClass {

  public static String mymethod(PageInfo pageinfo) {
       if (pageinfo != null && pageinfo.isFirst()) {
          return "<a href=\"first.jsp\">first</a>
       }
       return "";
  }
}


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.