Matt RaibleMatt Raible is a Web Developer and Java Champion. Connect with him on LinkedIn.

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.

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 01:31 PM 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 01:38 PM 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 02:06 PM 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 02:10 PM 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 02:45 PM 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 04:57 PM 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 05:00 PM 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 05:54 PM 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 06: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 06: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 04:51 PM MST #

Post a Comment:
  • HTML Syntax: Allowed