• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFS p408 problem passing parameter

 
Roger Yates
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following the code examples on page 408, I cannot get the parameter value to be displayed.

Here's the code I'm using:

Header.jspf



Contact.jsp


And here's what I get displayed:


I was kind-of hoping to see the text "We take the sting out of SOAP" instead I get the text "${param.subTitle}".

I even tried putting in a servlet mapping to see if that made a difference. (No).

-----------------------------

Having written all this - I just tried renaming Header.jspf file to Header.jsp instead and all works perfectly!

What is going on?
Should it work with a .jspf extension (as per e.g. in HFS) or is there a bug in Tomcat 5.0.28?!!


Anybody else tried this?
[ October 01, 2004: Message edited by: Roger Yates ]
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Uh. yeah. We did say it's a *convention*... we just forgot to point out that it doesn't work automatically by default, unless you provide a servlet mapping to tell the Container that it should treat every thing with a .jspf extension as a JSP.

To do this mapping,
you need to create a servlet mapping in which the servlet NAME is "jsp" all lower case and the url pattern is *.jspf. This tells the Container that everytime it sees a request for a .jspf thing, it is to treat this as a JSP and do the translation (which of course it does automatically with a *.jsp extension.

So, it's a convention (although not everyone uses it, and here's a perfect example of WHY), but it doesn't happen by default. So, you could use any extension you like, as long as you tell the Container using a mapping to show that, "Hey, this thing over here is to be treated as a JSP for the purposes of translation."

The reason that some people use .jspf instead of .jsp, is to make it explicit that this is a "segment" (used to be called "fragment", hence the "f" at the end), which means it should NOT have opening and closing tags, for example. Sorry about the confusion!

Geez Roger, you're smoking them ALL out! I'm predicting another successful exam for you...

Thanks!
-Kathy
 
Roger Yates
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again Kathy!

I've gone back to .jspf now and added the servlet mapping as you mentioned, (making sure I removed the 'deployed' .jsp of course!) and all works as designed!

It hadn't occurred to me that you could use a servlet mapping independently of a servlet entry. A neat trick!

All this, and I still only got 10/18 at the end of the chapter! That's a warning I need to brush up on my EL a bit more!
Incidentally, questions 2 and 6 use a single "'" for the el expressions, but it isn't until the next chapter that there's a comment saying that you can use either ' or " - meanie . (I nearly lost more points for assuming that they were invalid, but decided that, seeing how forgiving EL seemed to be, it'd probably allow it).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic