Get your CodeRanch badge!*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HFS p408 problem passing parameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HFS p408 problem passing parameter" Watch "HFS p408 problem passing parameter" New topic
Author

HFS p408 problem passing parameter

Roger Yates
Ranch Hand

Joined: Aug 31, 2004
Posts: 118
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 ]

Cheers,<br />Roger<br />SCJP 1.2, 1.4, SCBCD 1.3, SCWCD 1.4
Kathy Sierra
Cowgirl and Author
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
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

Joined: Aug 31, 2004
Posts: 118
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).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HFS p408 problem passing parameter
 
Similar Threads
jsp:param with jsp:include
using jsp:param
EL not displaying
HFSJ P408 jsp Include tag example
jspf not working with <jsp:include> and <jsp:param>