• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Scriptlets and expressions not executing in JSP page

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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
  • 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: 67266
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • 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
  • 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: 67266
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!