Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scriptlets and expressions not executing in JSP page

 
Jim Coble
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic