开发者

Modify JSTL import tag to show gzipped text in JSP

In my JSPs I am currently using JSTL to show the contents of simple text files that reside on a server as follows:

c:import url="http://www.mysite.com/texts/name_id.开发者_运维技巧txt" charEncoding="UTF-8"/>

These text files can be quite long and there are many of them so I want to compress them and serve the compressed version to the import tag. Can you give me some suggestions on how to modify the JSTL import tag, or create my own tag that achieves the same result when the text file is compressed? I suspect I should use Apache Commons Codec, or is java.util.zip enough?

For your reference, the source for the JSTL 1.2 import tag can be seen at:

http://grepcode.com/file/repo1.maven.org/maven2/javax.servlet/jstl/1.2/org/apache/taglibs/standard/tag/rt/core/ImportTag.java

http://grepcode.com/file/repo1.maven.org/maven2/javax.servlet/jstl/1.2/org/apache/taglibs/standard/tag/common/core/ImportSupport.java#ImportSupport

Regards


Create a servlet which is mapped on an URL pattern of /texts/* and does roughly the following job in doGet().

String path = request.getRequestURI().substring(request.getContextPath().length());
InputStream input = new GzipInputStream(getServletContext().getResourceAsStream(path));
OutputStream output = response.getOutputStream();
// Write input to output.

Note that the URL is based on your question and that you can keep your URLs in JSP unchanged this way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜