AppFuse中经过分析使用了大量的开源框架和组件。个人认为整个后台还不是强大,可能与它的定位有关联。我们在项目中积累了大量的Spring以及Hibernate应用都要比之要强很多。但appFuse的前台整合还是相当不错的。先学一个gzipFilter
gzipFilter其实就位于eHcache里面,他是将response中的东东都压缩一下,这个可大大减少了传输时间。
配置web.xml
效果,你可以用FoxFire的net看各个css,js文件可是压缩50%以上哦。
写了一个jsp文件专门评估
gzipFilter其实就位于eHcache里面,他是将response中的东东都压缩一下,这个可大大减少了传输时间。
配置web.xml
- <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文件专门评估
- <%@pagelanguage="java"import="java.util.*,java.net.*,java.io.*"
- pageEncoding="ISO-8859-1"%>
- <%
- Stringpath=request.getContextPath();
- StringbasePath=request.getScheme()+"://"
- +request.getServerName()+":"+request.getServerPort()
- +path+"/";
- %>
- <%
- Stringurl=request.getParameter("url");
- if(url!=null){
- URLnoCompress=newURL(url);
- HttpURLConnectionhuc=(HttpURLConnection)noCompress
- .openConnection();
- huc.setRequestProperty("user-agent","Mozilla(MSIE)");
- huc.connect();
- ByteArrayOutputStreambaos=newByteArrayOutputStream();
- InputStreamis=huc.getInputStream();
- while(is.read()!=-1){
- baos.write((byte)is.read());
- }
- byte[]b1=baos.toByteArray();
- URLcompress=newURL(url);
- HttpURLConnectionhucCompress=(HttpURLConnection)noCompress
- .openConnection();
- hucCompress.setRequestProperty("accept-encoding","gzip");
- hucCompress.setRequestProperty("user-agent","Mozilla(MSIE)");
- hucCompress.connect();
- ByteArrayOutputStreambaosCompress=newByteArrayOutputStream();
- InputStreamisCompress=hucCompress.getInputStream();
- while(isCompress.read()!=-1){
- baosCompress.write((byte)isCompress.read());
- }
- byte[]b2=baosCompress.toByteArray();
- request.setAttribute("t1",newInteger(b1.length));
- request.setAttribute("t2",newInteger(b2.length));
- request.setAttribute("t3",(1-newDouble(b2.length)
- /newDouble(b1.length))*100);
- }
- request.setAttribute("url",url);
- %>
- <!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
- <html>
- <head>
- <basehref="<%=basePath%>">
- <title>MyJSP'MyJsp.jsp'startingpage</title>
- <metahttp-equiv="pragma"content="no-cache">
- <metahttp-equiv="cache-control"content="no-cache">
- <metahttp-equiv="expires"content="0">
- <metahttp-equiv="keywords"content="keyword1,keyword2,keyword3">
- <metahttp-equiv="description"content="Thisismypage">
- <!--
- <linkrel="stylesheet"type="text/css"href="styles.css">
- -->
- </head>
- <body>
- ThisismyJSPpage.
- <br>
- <h1>
- CompressionTest
- </h1>
- EnteraURLtotest.
- <formmethod="POST">
- <inputname="url"size="50">
- <inputtype="submit"value="CheckURL">
- </form>
- <p>
- <%=url%>
- <b>Testing:${url}</b>
- </p>
- Request1:${t1}bytes
- <%=request.getAttribute("t1")%>
- <br/>
- Request2:${t2}bytes
- <%=request.getAttribute("t2")%>
- <br/>
- Spacesaved:${t1-t2}bytesor${(1-t2/t1)*100}%
- <%=request.getAttribute("t3")%>%
- <br/>
- </body>
- </html>