日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Appfuse2学习笔记--GzipFilter的应用

發(fā)布時間:2025/3/17 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Appfuse2学习笔记--GzipFilter的应用 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
AppFuse中經(jīng)過分析使用了大量的開源框架和組件。個人認為整個后臺還不是強大,可能與它的定位有關(guān)聯(lián)。我們在項目中積累了大量的Spring以及Hibernate應(yīng)用都要比之要強很多。但appFuse的前臺整合還是相當(dāng)不錯的。先學(xué)一個gzipFilter
gzipFilter其實就位于eHcache里面,他是將response中的東東都壓縮一下,這個可大大減少了傳輸時間。
配置web.xml
Java代碼 ?
  • <filter> ??
  • ????????<filter-name>gzipFilter</filter-name> ??
  • ????????<filter-class> ??
  • ????????????net.sf.ehcache.constructs.web.filter.GzipFilter ??
  • ????????</filter-class> ??
  • ????</filter> ??
  • <filter-mapping> ??
  • ????????<filter-name>gzipFilter</filter-name> ??
  • ????????<url-pattern>*.css</url-pattern> ??
  • ????</filter-mapping> ??
  • ????<filter-mapping> ??
  • ????????<filter-name>gzipFilter</filter-name> ??
  • ????????<url-pattern>*.png</url-pattern> ??
  • ????</filter-mapping> ??
  • ????<filter-mapping> ??
  • ????????<filter-name>gzipFilter</filter-name> ??
  • ????????<url-pattern>*.gif</url-pattern> ??
  • ????</filter-mapping> ??
  • ????<filter-mapping> ??
  • ????????<filter-name>gzipFilter</filter-name> ??
  • ????????<url-pattern>*.html</url-pattern> ??
  • ????</filter-mapping> ??
  • ????<filter-mapping> ??
  • ????????<filter-name>gzipFilter</filter-name> ??
  • ????????<url-pattern>*.jsp</url-pattern> ??
  • ????</filter-mapping> ??
  • ????<filter-mapping> ??
  • ????????<filter-name>gzipFilter</filter-name> ??
  • ????????<url-pattern>*.js</url-pattern> ??
  • ????</filter-mapping> ??
  • ????<filter-mapping> ??
  • ????????<filter-name>gzipFilter</filter-name> ??
  • ????????<url-pattern>*.json</url-pattern> ??
  • ????</filter-mapping>??
  • <filter><filter-name>gzipFilter</filter-name><filter-class>net.sf.ehcache.constructs.web.filter.GzipFilter</filter-class></filter> <filter-mapping><filter-name>gzipFilter</filter-name><url-pattern>*.css</url-pattern></filter-mapping><filter-mapping><filter-name>gzipFilter</filter-name><url-pattern>*.png</url-pattern></filter-mapping><filter-mapping><filter-name>gzipFilter</filter-name><url-pattern>*.gif</url-pattern></filter-mapping><filter-mapping><filter-name>gzipFilter</filter-name><url-pattern>*.html</url-pattern></filter-mapping><filter-mapping><filter-name>gzipFilter</filter-name><url-pattern>*.jsp</url-pattern></filter-mapping><filter-mapping><filter-name>gzipFilter</filter-name><url-pattern>*.js</url-pattern></filter-mapping><filter-mapping><filter-name>gzipFilter</filter-name><url-pattern>*.json</url-pattern></filter-mapping>

    效果,你可以用FoxFire的net看各個css,js文件可是壓縮50%以上哦。
    寫了一個jsp文件專門評估
    Java代碼 ?
  • <%@?page?language="java"?import="java.util.*,java.net.*,java.io.*"??
  • ????pageEncoding="ISO-8859-1"%> ??
  • <% ??
  • ????String?path?=?request.getContextPath(); ??
  • ????String?basePath?=?request.getScheme()?+?"://"??
  • ????????????+?request.getServerName()?+?":"?+?request.getServerPort() ??
  • ????????????+?path?+?"/"; ??
  • %> ??
  • <% ??
  • ????String?url?=?request.getParameter("url"); ??
  • ????if?(url?!=?null)?{ ??
  • ????????URL?noCompress?=?new?URL(url); ??
  • ????????HttpURLConnection?huc?=?(HttpURLConnection)?noCompress ??
  • ????????????????.openConnection(); ??
  • ????????huc.setRequestProperty("user-agent",?"Mozilla(MSIE)"); ??
  • ????????huc.connect(); ??
  • ????????ByteArrayOutputStream?baos?=?new?ByteArrayOutputStream(); ??
  • ????????InputStream?is?=?huc.getInputStream(); ??
  • ????????while?(is.read()?!=?-1)?{ ??
  • ????????????baos.write((byte)?is.read()); ??
  • ????????} ??
  • ????????byte[]?b1?=?baos.toByteArray(); ??
  • ??
  • ????????URL?compress?=?new?URL(url); ??
  • ????????HttpURLConnection?hucCompress?=?(HttpURLConnection)?noCompress ??
  • ????????????????.openConnection(); ??
  • ????????hucCompress.setRequestProperty("accept-encoding",?"gzip"); ??
  • ????????hucCompress.setRequestProperty("user-agent",?"Mozilla(MSIE)"); ??
  • ????????hucCompress.connect(); ??
  • ????????ByteArrayOutputStream?baosCompress?=?new?ByteArrayOutputStream(); ??
  • ????????InputStream?isCompress?=?hucCompress.getInputStream(); ??
  • ????????while?(isCompress.read()?!=?-1)?{ ??
  • ????????????baosCompress.write((byte)?isCompress.read()); ??
  • ????????} ??
  • ????????byte[]?b2?=?baosCompress.toByteArray(); ??
  • ????????request.setAttribute("t1",?new?Integer(b1.length)); ??
  • ????????request.setAttribute("t2",?new?Integer(b2.length)); ??
  • ????????request.setAttribute("t3",?(1?-?new?Double(b2.length) ??
  • ????????????????/?new?Double(b1.length))?*?100); ??
  • ????} ??
  • ????request.setAttribute("url",?url); ??
  • %> ??
  • <!DOCTYPE?HTML?PUBLIC?"-//W3C//DTD?HTML?4.01?Transitional//EN"> ??
  • <html> ??
  • ????<head> ??
  • ????????<base?href="<%=basePath%>"> ??
  • ??
  • ????????<title>My?JSP?'MyJsp.jsp'?starting?page</title> ??
  • ??
  • ????????<meta?http-equiv="pragma"?content="no-cache"> ??
  • ????????<meta?http-equiv="cache-control"?content="no-cache"> ??
  • ????????<meta?http-equiv="expires"?content="0"> ??
  • ????????<meta?http-equiv="keywords"?content="keyword1,keyword2,keyword3"> ??
  • ????????<meta?http-equiv="description"?content="This?is?my?page"> ??
  • ????????<!-- ??
  • ????<link?rel="stylesheet"?type="text/css"?href="styles.css"> ??
  • ????--> ??
  • ??
  • ????</head> ??
  • ??
  • ????<body> ??
  • ????????This?is?my?JSP?page. ??
  • ????????<br> ??
  • ????????<h1> ??
  • ????????????Compression?Test ??
  • ????????</h1> ??
  • ????????Enter?a?URL?to?test. ??
  • ????????<form?method="POST"> ??
  • ????????????<input?name="url"?size="50"> ??
  • ????????????<input?type="submit"?value="Check?URL"> ??
  • ????????</form> ??
  • ????????<p> ??
  • ????????????<%=url%> ??
  • ????????????<b>Testing:?${url}</b> ??
  • ????????</p> ??
  • ????????Request?1:?${t1}?bytes ??
  • ????????<%=request.getAttribute("t1")%> ??
  • ????????<br?/> ??
  • ????????Request?2:?${t2}?bytes ??
  • ????????<%=request.getAttribute("t2")%> ??
  • ????????<br?/> ??
  • ????????Space?saved:?${t1-t2}?bytes?or?${(1-t2/t1)*100}% ??
  • ????????<%=request.getAttribute("t3")%>% ??
  • ????????<br?/> ??
  • ????</body> ??
  • </html> ?
  • 總結(jié)

    以上是生活随笔為你收集整理的Appfuse2学习笔记--GzipFilter的应用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。