aspose file tools*
The moose likes Tomcat and the fly likes Scriptlets and expressions not executing in JSP page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Scriptlets and expressions not executing in JSP page" Watch "Scriptlets and expressions not executing in JSP page" New topic
Author

Scriptlets and expressions not executing in JSP page

Jim Coble
Greenhorn

Joined: Oct 27, 2002
Posts: 10
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<br />SCJP 1.4<br />SCWCD 1.4
Jim Coble
Greenhorn

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

Joined: Jan 10, 2002
Posts: 61661
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jim Coble
Greenhorn

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

Joined: Jan 10, 2002
Posts: 61661
    
  67

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Scriptlets and expressions not executing in JSP page