20031024 Friday October 24, 2003

How can I import local html/text files into a JSP page? I posted the following message to the taglibs-user mailing list, but thought I'd do it here as well - since I know I have some smart readers.

I have a requirement to allow reading of "assets" for a website from a local CD. These assets might be images, flash movies, html/text pages, etc. I've got everything working but rendering html/text. When I do the rendering of text/html online, I use <c:import url="/assets/filename.html"/>, and offline, I do <c:import url="file:///e:/assets/filename.html"/>. I can enter this fine in Mozilla and the page will come up, but JSTL's c:import tag says it can't find the file.

2 questions:

1. Can I use c:import to import a local HTML file onto a page?
2. If not, is there any way to do this?

Any ideas? Posted in Java at Oct 24 2003, 06:02:01 AM MDT 11 Comments

Comments:

Obviously the JSTL tag is server-side processed before being sent to the user. Maybe the only way for you to do this is to not use any taglibs and stick with plain HTML so you force the browser to 'process' the tag?

Posted by Pratik Patel on October 24, 2003 at 07:31 AM MDT #

The problem is that I'm actually <em>including</em> the HTML (or text) into part of an HTML page. This page can have 1-n "assets" so the text asset might just be a smart part of the page, alongside images, flash movies, etc. Since users still have to be online to view the course (it's an e-learning app), maybe I should just keep text/html assets rendered from the server, and the other ones (which can get very large - think QuickTime movies), render those from the CD.

Posted by Matt Raible on October 24, 2003 at 07:38 AM MDT #

Maybe <c:import url="<%= request.getContextPath() %>/assets/filename.html"/> or: <!@ import file="<%= request.getContextPath() %>/assets/filename.html" flush="true" /> I'm a JSP newbie, so these probably won't work, just throwing ideas out.

Posted by Marc Adams on October 24, 2003 at 08:06 AM MDT #

Code needed to be formatted, my bad. <c:import url="<%= request.getContextPath() %>/assets/filename.html"/> or: <!@ import file="<%= request.getContextPath() %>/assets/filename.html" flush="true" />

Posted by Marc Adams on October 24, 2003 at 08:10 AM MDT #

Thanks for the suggestions Marc, but as Pratik pointed out (and someone on the taglibs-user mailing list), this is not possible with <c:import url=""/>.

Posted by Matt Raible on October 24, 2003 at 08:45 AM MDT #

Doesn't a standard <jsp:include /> do what you want? I believe a <jsp:include file="<%= request.getContextPath() + "/assets/..." %>" /> should work, as long as the inline function returns the whole string.

Posted by Cameron Gray on October 24, 2003 at 10:57 AM MDT #

Gahhh.... jsp:include is meant to appear there, as long as for the file= you return the full path instead of expecting it to concatenate itself should work. The inline Java will be processed before the doStartTag call... i.e. file = ' \<%= request.... + " /assets etc... \%>

Posted by Cameron Gray on October 24, 2003 at 11:00 AM MDT #

The problem is that I can specify a local path for images - i.e. c:\images - and using that as an image's src works just fine (it looks on the user's local hard drive). However, if I use c:\text in a <jsp:include> tag, it'll try to include that file from <strong>it's hard drive</strong>, rather than mine. So, basically, it's not possible to import client side text with JSP tags.

The workaround I'm going to go with is to continue to import HTML and Text assets from the server, and only use the client's local path for media files. Of course, the app I'm developing only does this when the user states that they want to use a local CD for their files (vs. the online versions). This results in much faster downloading for large assets.

Posted by Matt Raible on October 24, 2003 at 11:54 AM MDT #

use a servlet to return different mime types. then call servlet?file=bleh&type=gif

Posted by Cameron Gray on October 24, 2003 at 12:10 PM MDT #

I could imagine importing local files might be possible with JavaScript and DOM (innerHtml/Text properties, etc), unless it breaks some kinda security rules - it can't see it being a 1 liner like a c:import tag tho.

Posted by Graham on October 25, 2003 at 12:20 AM MDT #

c:import doesn't work because the server has to be able to download the file from the url specified, and (presumably) there's no web server on the user's machine. An iframe might work for the text.

Posted by Jay Dunning on October 27, 2003 at 09:51 AM MST #

Post a Comment:
  • HTML Syntax: Allowed
Click me to subscribe
Matt Raible is a Web Architect who enjoys developing applications with open source technologies. Contact me for rates.
« November 2008
SunMonTueWedThuFriSat
      
1
2
3
6
7
8
9
10
11
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
      
Today

Recent Entries

Tag Cloud