what page am I generating


R

Roedy Green

I have looked in what I would consider to be the obvious places
without success. How does a doTag method find out the name of the
page it is generating? Does the concept exist in JSP?
--
Roedy Green Canadian Mind Products
http://mindprod.com

Nothing is so good as it seems beforehand.
~ George Eliot (born: 1819-11-22 died: 1880-12-22 at age: 61) (Mary Ann Evans)
 
Ad

Advertisements

D

Daniel Pitts

Roedy said:
I have looked in what I would consider to be the obvious places
without success. How does a doTag method find out the name of the
page it is generating? Does the concept exist in JSP?

PageContext is the entry point to the object graph you are probably
caring about.

there is a method setPageContext on the Tag interface.

TagSupport sets a protected field pageContext with the value.

pageContext.getRequest() will return the current servlet request.
 
M

markspace

Roedy said:
I have looked in what I would consider to be the obvious places
without success. How does a doTag method find out the name of the
page it is generating? Does the concept exist in JSP?


I think Daniel hass it, but just to repeat:

1. Your Java class needs to extend javax.servlet.js.target.SimpleTagSupport.

2. You create a TLD file. The <tag> has an element <tag-class> which
names your class from #1 above, and a <name> element which names the tag
for #3 below. I assume that the class file is found in the usual way
for a JEE app.

3. When you create the page, you use a taglib directive (?) to indicate
the taglib from #2.

<%@ taglib prefix="myTags" uri="taglib name">

There's a standard search path for finding tablibs indicated by this
directive. It varies depending if you have like 1.x or 2.0+ container,
iirc.
 
M

markspace

markspace said:
2. You create a TLD file. The <tag> has an element <tag-class> which
names your class from #1 above, and a <name> element which names the tag
for #3 below. I assume that the class file is found in the usual way
for a JEE app.


Oops, the TLD file has a <uri> element which is used to match the uri
attribute in the directive. The <name> field is used elsewhere.
 
D

Donkey Hottie

21.10.2009 2:58, markspace kirjoitti:
Oops, the TLD file has a <uri> element which is used to match the uri
attribute in the directive. The <name> field is used elsewhere.

Hmm..

If not sure if this is the right path to jsp.. But then again, somehow
knowing Roedy (from the Internet, not otherwise).. then maybe it is..

One have to be one perfectionist and end up with his own JSP
implementation soon enough following this route!

First things first, and try to Focus and all that ;D
 
M

markspace

Donkey said:
If not sure if this is the right path to jsp.. But then again, somehow
knowing Roedy (from the Internet, not otherwise).. then maybe it is..


Oh, I think I see what you mean. Well, there's a
"SimpleTagSupport.getPageContext" method, that should get you anything
you need.

I don't see why the actual name of the scriptlet should be important.
It's like hard coding some behavior based on class name. That would be
bad. Add an attribute to the page context and let the tag look for that
attribute, if you must. That's injectable behavior. The reverse --
what is the name of my caller? -- is just an ugly idea.
 
Ad

Advertisements

R

Roedy Green

I don't see why the actual name of the scriptlet should be important.
It's like hard coding some behavior based on class name.

Why?

I want to track hit counts. I need something analogous to the HTML
file name to track them by.

I want to display the URL of the page on the footer so that if anyone
prints a snapshot of the page, they know where the original came from.

I have a rule based scheme for generating random quotations, that uses
the filename/directory name to weight what sorts of quotations show
up. Ditto PSA ads.

I also need it to generate terse relative links to other pages. I
specify some links in markup as webroot relative, and convert them to
relative. This way I can insert boilerplate containing links anywhere
in the tree and all works. There may be another way of handling that
with TagLibs.


--
Roedy Green Canadian Mind Products
http://mindprod.com

Nothing is so good as it seems beforehand.
~ George Eliot (born: 1819-11-22 died: 1880-12-22 at age: 61) (Mary Ann Evans)
 
C

ck

This seems to work. It seems rather roundabout.

// webroot relative URL of page we are generating.
final String wrURL =( (HttpServletRequest)
pageContext.getRequest()).getRequestURI();

Or you can use JavaScript (I know some people might be provoked with
this idea). "window.history" object should do the trick for most of
the browser (and javascript not disabled).

window.history.current
 
M

markspace

Roedy said:

Really? You want to peek the return address of your caller and you're
asking me why that's a bad idea? Seriously?

I want to track hit counts. I need something analogous to the HTML
file name to track them by.


You know there's almost correspondence between your caller and the URL
that the user typed in, right? All that stuff is set in the deployment
descriptor. URLs are mapped to scriptlets (and JSPs are scriptlets) and
the name of the script doesn't really come into play there.

Sniffing URL's is fine, I support that. The URL is passed as a
parameter with the Request object. Looking at parameters is fine, I
support that. Sniffing your caller's stack frame, not so much.

I want to display the URL of the page on the footer so that if anyone
prints a snapshot of the page, they know where the original came from.

I do have to criticize you for using very loose terminology. The name
of a scriptlet has nothing to do with the URL, other than what the
deployment descriptor says it does. If you wanted the URL you should
have said.

I have a rule based scheme for generating random quotations, that uses
the filename/directory name to weight what sorts of quotations show
up. Ditto PSA ads.


This sounds like a Java class to me, so you can isolate the rest of the
application from these implementation details.
I also need it to generate terse relative links to other pages. I

This sounds like you might want to consider manipulating the deployment
descriptor. Send terse links to other pages/scriptlets with the
deployment descriptor.

specify some links in markup as webroot relative, and convert them to
relative. This way I can insert boilerplate containing links anywhere
in the tree and all works. There may be another way of handling that
with TagLibs.

I don't know what the difference between "webroot relative" and
"relative" is, so no opinion here. You might want to consider making a
very small, SSCCE style sample app, with one implementation of each
use-case that you think you need, posting it up somewhere (Google apps?
Your own site?) and letting folks comment on it.
 
L

Lew

  I know now at least two persons who usually end sentences
  with »..«. Does anyone know why they do this?

Because they are ignorant of the rules of English punctuation.
perhaps?
 
Ad

Advertisements

R

RedGrittyBrick

Stefan said:
I know now at least two persons who usually end sentences
with »..«. Does anyone know why they do this?

Their keyboard has a broken … key?
 
R

Roedy Green

I don't know what the difference between "webroot relative" and
"relative" is, so no opinion here.

If I have an URL http://mindprood.com/jgloss/taglibs.html then I call
jgloss/taglibs.html the "webroot-relative" or "wr" address.

If I have a link from that page to http://mindprood.com/project/x.html

the href to get there looks like ../project/x.html

I call that the "relative" address.

Do these things have official names?
--
Roedy Green Canadian Mind Products
http://mindprod.com

Nothing is so good as it seems beforehand.
~ George Eliot (born: 1819-11-22 died: 1880-12-22 at age: 61) (Mary Ann Evans)
 
R

Roedy Green

I would call both of those relative URLs. Not addresses, URLs. And not
webroot, just relative.

Ok, but in code that generates HTML, they are quite different animals.
You need to give them some sort of distinctive name.

A webroot URL is invariant no matter where it is appears in the tree
of documents. Webroot URLs are handy for boiler plate included in
various places in the tree.

However, unfortunately HTML does not directly support webroot URLs.
You must convert one to a relative URL to use it in an HREF. What you
convert it into depends on the page where the HREF is.

--
Roedy Green Canadian Mind Products
http://mindprod.com

Nothing is so good as it seems beforehand.
~ George Eliot (born: 1819-11-22 died: 1880-12-22 at age: 61) (Mary Ann Evans)
 
R

Roedy Green

Because they are ignorant of the rules of English punctuation.
perhaps?

Shakespear felt free to make up new spelling and grammar. Online,
people feel free of all restrictions, with the excuse of brevity for
thumb texting.

I think .. is intended to indicate a shorter pause than ... Compared
with "wanna", "gimme", "yer", "gr8", "cud", "cn" it is a minor sin.

I find most amusing is a request for help getting a job written in
text speak.
--
Roedy Green Canadian Mind Products
http://mindprod.com

Nothing is so good as it seems beforehand.
~ George Eliot (born: 1819-11-22 died: 1880-12-22 at age: 61) (Mary Ann Evans)
 
Ad

Advertisements

A

Arne Vajhøj

ck said:
Or you can use JavaScript (I know some people might be provoked with
this idea). "window.history" object should do the trick for most of
the browser (and javascript not disabled).

window.history.current

It will solve the show URL at the bottom problem but not the hit
counter problem.

Arne
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

JSP including 12
string case clauses 7
Pithy programming Quotations 23
writing to DVD 1
What is a "fresher"? 25
Offsite JSP 18
Basic JSP question 17
Java hom foer the Mac Snow Leopard? 7

Top