Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Custom Tags

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
You are using a tag library with prefix "generator" which supports a tag named "random". This tag generates a random number and sets it to a variable named "value". Which of the following will output this value in the page?
The answer is <generator.random><%=value%></generator.random>
Please, can somebody write a example of how do a tag library with prefix "generator" and a tag named "random"?
Thank you in advance
 
Ranch Hand
Posts: 2166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jordi,
what are the other wrong answers? Maybe then its easier to discuss.
Axel
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I think that the question is not how I would like because my english is not good.
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jordi:
I don't think the ans is correct, atleast I don't know how to write such a tag...
However, the closest example code I could get is enclosed here.
Files:
  • RandomNumExample.jsp: Put this in %Catalina_Home%\webapps\Root\jsp-intro
  • random-taglib.tld: Put this in %Catalina_Home%\webapps\Root\WEB-INF
  • web.xml: Put this in %Catalina_Home%\webapps\Root\WEB-INF
  • RandomTag.java: Compile this file and put the RandomTag.class file in %Catalina_Home%\webapps\Root\WEB-INF\classes\madhav\tags


  • Then you can access it through the URL:
    http://localhost:8080/jsp-intro/RandomNumExample.jsp

    This is the closest example I could getto, with the explanation given.
    - satya
    ps:
    As you can make out, this example is based on an example from More Servlets and JSP's book.
    [ February 05, 2002: Message edited by: Madhav Lakkapragada ]
     
    Anonymous
    Ranch Hand
    Posts: 18944
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you very much Madhav
     
    Sheriff
    Posts: 5782
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I am not a tag-guru, but I know JSP tag usage rules follow XML standards. Most certainly the "prefix" here means a namespace declared by the taglib. In XML, tags belonging to a namespace are always qualified with "prefix:"
    So whatever is the expression for invoking the java code, the enclosing tags should be of the form
    <generator:random>
    something here
    </generator.random>
    [ February 07, 2002: Message edited by: Ajith Kallambella ]
     
    He baked a muffin that stole my car! And this tiny ad:
    Devious Experiments for a Truly Passive Greenhouse!
    https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
      Bookmark Topic Watch Topic
    • New Topic