473,327 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Get rid of scriptlet and put in class

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.

Expand|Select|Wrap|Line Numbers
  1. <jsp:useBean id="pageinfo" class="mypackage.PageInfo" scope="session"/>
  2. ...
  3. <%
  4. if (pageinfo!=null) {
  5.    if (pageinfo.isFirst()) {
  6.        out.println("<a href=first.jsp>first</a>");
  7.      }
  8. }
  9. %>
  10.  
Would this be close because I am not sure how to create the method?
Expand|Select|Wrap|Line Numbers
  1. //in the class file
  2. package mypackage;
  3. import mypackage.pageinfo;
  4.  
  5. public String mymethod()
  6. {
  7. if (pageinfo!=null) {
  8.    if (pageinfo.isFirst()) {
  9.        out.println("<a href=first.jsp>first</a>");
  10.      }
  11. }
  12. }
  13.  
Then call it like this in JSP?
Expand|Select|Wrap|Line Numbers
  1. <% mymethod(); %>
  2.  

I dont have JSTL or Struts on this Tomcat 4.1.27 container that I am working on.
Aug 29 '07 #1
3 1915
dmjpro
2,476 2GB
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.

Expand|Select|Wrap|Line Numbers
  1. <jsp:useBean id="pageinfo" class="mypackage.PageInfo" scope="session"/>
  2. ...
  3. <%
  4. if (pageinfo!=null) {
  5.    if (pageinfo.isFirst()) {
  6.        out.println("<a href=first.jsp>first</a>");
  7.      }
  8. }
  9. %>
  10.  
Would this be close because I am not sure how to create the method?
Expand|Select|Wrap|Line Numbers
  1. //in the class file
  2. package mypackage;
  3. import mypackage.pageinfo;
  4.  
  5. public String mymethod()
  6. {
  7. if (pageinfo!=null) {
  8.    if (pageinfo.isFirst()) {
  9.        out.println("<a href=first.jsp>first</a>");
  10.      }
  11. }
  12. }
  13.  
Then call it like this in JSP?
Expand|Select|Wrap|Line Numbers
  1. <% mymethod(); %>
  2.  

I dont have JSTL or Struts on this Tomcat 4.1.27 container that I am working on.

I think you can do it by using..............!!
Just simply return the HTML String to the JSP then your Scriptlet Code will be reduced.
What do you think?

Kind regards,
Dmjpro.
Aug 30 '07 #2
r035198x
13,262 8TB
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.

Expand|Select|Wrap|Line Numbers
  1. <jsp:useBean id="pageinfo" class="mypackage.PageInfo" scope="session"/>
  2. ...
  3. <%
  4. if (pageinfo!=null) {
  5.    if (pageinfo.isFirst()) {
  6.        out.println("<a href=first.jsp>first</a>");
  7.      }
  8. }
  9. %>
  10.  
Would this be close because I am not sure how to create the method?
Expand|Select|Wrap|Line Numbers
  1. //in the class file
  2. package mypackage;
  3. import mypackage.pageinfo;
  4.  
  5. public String mymethod()
  6. {
  7. if (pageinfo!=null) {
  8.    if (pageinfo.isFirst()) {
  9.        out.println("<a href=first.jsp>first</a>");
  10.      }
  11. }
  12. }
  13.  
Then call it like this in JSP?
Expand|Select|Wrap|Line Numbers
  1. <% mymethod(); %>
  2.  

I dont have JSTL or Struts on this Tomcat 4.1.27 container that I am working on.
Just put the method in a class, import that class in your JSP and you should be able to call the method using ClassName.methodName if you mabe it static otherwise you'd have to create an instance of that class in your JSP.
Aug 30 '07 #3
Just put the method in a class, import that class in your JSP and you should be able to call the method using ClassName.methodName if you mabe it static otherwise you'd have to create an instance of that class in your JSP.
Thanks I got it to work just as you suggested.

Now I am trying the same thing with one more scriptlet in my JSP. But this JSP scriptlet has a for loop that outputs 10 links on the page:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <jsp:useBean id="pageinfo" class="storm.Pageinfo" scope="session" />
  3. .....
  4. <%     
  5. if (pageinfo!=null)
  6.  {
  7.       for(int i=0;i < 10;i++)
  8.      { 
  9.           out.println("<a href=moveto.jsp?inpage=" + i + ">" + i + "</a>");
  10.      }        
  11.  
  12. %>
  13.  
Now my attempt to put it in a class outputs only 1 link instead of 10.
JSP scriptlet calling the static method:
Expand|Select|Wrap|Line Numbers
  1. <%= PageUtil.theMethod(pageinfo)  %>
  2.  
Source code for the PageUtil.java:
Expand|Select|Wrap|Line Numbers
  1. package storm;
  2. import storm.*;
  3.  
  4. public class PageUtil
  5. {
  6.        public static String theMethod(Pageinfo pageinfo)
  7.        {
  8.            if (pageinfo!=null)
  9.            {
  10.               for(int i=0;i < 10;i++)
  11.               { 
  12.                  return "<a href=moveto.jsp?inpage=" + i + ">" + i + "</a>";
  13.               }        
  14.            } 
  15.        return "";
  16.        }
  17. }
  18.  
Please advise how I can get this to work?
Aug 31 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Thomas Born | last post by:
Hi; I use following code in an ASP page to generate a GUID: <% dim obj Set obj = Server.CreateObject("Scriptlet.TypeLib") Response.Write(obj.guid) Set obj = nothing %>
0
by: Lim Chee H | last post by:
Hi All, I have an ASP calling a scriptlet. There is a method "Exec" which is using Server.Execute to run any ASP file/command. There rest of the methods are working fine.Somehow,...
2
by: Hats | last post by:
Hi, I've a site with no php, but ssi and scriptlets do work. I tried these tags. ++++++++++++++++++++++++++++++++++++++++++++++++++ <object type="text/x-scriptlet"...
3
by: eddie | last post by:
Hi, my colleague wrote a scriptlet to get server wide environment variables from ASP. However, my web application is written by C#, and I try to write a program to access that COM but I always get...
2
by: ze colmeia | last post by:
Hi all... i'm having trouble trying to pass a field value from a Data Access Page to a Scriptlet. Om my DAP i have: Function returnId() Dim pId pId = formName.Id.value returnId = pId
8
by: abctech | last post by:
Hi All, I have a dynamic table in my web page which I'm creating in a jsp-scriptlet - <html> <body> <% out.write("<table>") ; // code to add rows dynamically to the table from my...
9
by: unlikeablePorpoise | last post by:
I would like to have an HTML dropdown list where each selection calls a method. The following code doesn't work, but it I hope it gives the idea of what I'm trying to do: <FORM NAME="frm">...
1
by: inf | last post by:
How can i use java script variable in java scriptlet
2
by: freedom9ner | last post by:
Hello, I'm investigating how HTML can be componentized and reusable. Remember Microsoft's SCRIPTLET object (TYPE="text/x-scriptlet")? I thought this was a great invention. But other browsers do not...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.