• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Scriptlets and expressions not executing in JSP page

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have deployed a Java web app in a Tomcat 6.0.24 instance and scriptlets and expressions are being passed through as HTML without being executed. For example, my JSP page contains the following code:



When I view the resulting HTML page, instead of seeing something like "Last generated September 20, 2011 4:11:33 PM EDT", I am seeing "<% java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("MMMM d, yyyy h:mm:ss a z"); %> Last generated <%= sdf.format(new java.util.Date()) %>".

Any ideas why this might be?

Thanks in advance for any help you can provide.

--Jim
 
Jim Coble
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I figured out the source of the problem. The scriptlets and expressions that weren't executing were in .jspf files. I needed to add the following servlet-mapping to the web.xml file in Tomcat's conf directory ...

Once I had done that, the scriptlets and expressions executed correctly.
--Jim
 
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should not have to add that mapping. In fact, it's a bad idea to do so.

The .jspf file type should only be used on files included via the include directive. Files included with the include action should have a file type of .jsp.
 
Jim Coble
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:You should not have to add that mapping. In fact, it's a bad idea to do so.

The .jspf file type should only be used on files included via the include directive. Files included with the include action should have a file type of .jsp.



I didn't know that. Our .jspf files are being "included" using the Apache Tiles 2 framework. I'm curious why it's a "bad idea" to use the .jspf extension the way we are. I don't doubt that it is ... otherwise the .jspf servlet-mapping would have been included in the default web.xml ... just curious as to why.

--Jim
 
Bear Bibeault
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because, by convention, the .jspf file type is exclusively for static JSP fragments that are included via the include directive. This means that they are not interpreted at the time of inclusion, but along with the including page, and do not need to be syntactically complete JSP files. Files included in places where the interpretation happens at include time should use the .jsp file type so that they are properly processed by the JSP engine without the need for unconventional mappings, and must be syntactically complete JSPs.

The "f" in .jspf stands for "fragment". Statically included files can be fragments, dynamically included files cannot be. So naming them .jspf is not only unconventional, but a misrepresentation of the contents of the file.
 
reply
    Bookmark Topic Watch Topic
  • New Topic