web.xml配置中的

  1. <mime-mapping>  
  2. <extension>doc</extension>  
  3. <mime-type>application/msword</mime-type>  
  4. </mime-mapping>  
  5. <mime-mapping>  
  6. <extension>xls</extension>  
  7. <mime-type>application/msexcel</mime-type>  
  8. </mime-mapping>  
  9. <mime-mapping>  
  10. <extension>pdf</extension>  
  11. <mime-type>application/pdf</mime-type>  
  12. </mime-mapping>  
  13. <mime-mapping>  
  14. <extension>zip</extension>  
  15. <mime-type>application/zip</mime-type>  
  16. </mime-mapping>  
  17. <mime-mapping>  
  18. <extension>rar</extension>  
  19. <mime-type>application/rar</mime-type>  
  20. </mime-mapping>  
  21. <mime-mapping>  
  22. <extension>txt</extension>  
  23. <mime-type>application/txt</mime-type>  
  24. </mime-mapping>  
  25. <mime-mapping>  
  26. <extension>chm</extension>  
  27. <mime-type>application/mshelp</mime-type>  
  28. </mime-mapping>  
  29. <mime-mapping>  
  30. <extension>mp3</extension>  
  31. <mime-type>audio/x-mpeg</mime-type>  
  32. </mime-mapping>   


常见的MIME类型

超文本标记语言文本 .htm,.html text/html
普通文本 .txt text/plain
RTF文本 .rtf application/rtf
GIF图形 .gif image/gif
JPEG图形 .ipeg,.jpg image/jpeg
au声音文件 .au audio/basic
MIDI音乐文件 mid,.midi audio/midi,audio/x-midi
RealAudio音乐文件 .ra, .ram audio/x-pn-realaudio
MPEG文件 .mpg,.mpeg video/mpeg
AVI文件 .avi video/x-msvideo
GZIP文件 .gz application/x-gzip
TAR文件 .tar application/x-tar


1.指定了自己的javaEncoding

<servlet>
       <servlet-name>jsp</servlet-name>
       <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
       <init-param>
           <param-name>fork</param-name>
           <param-value>false</param-value>
       </init-param>
               <init-param>
           <param-name>javaEncoding</param-name>
           <param-value>GB18030</param-value>
       </init-param>
       <init-param>
           <param-name>xpoweredBy</param-name>
           <param-value>true</param-value>
       </init-param>
       <load-on-startup>3</load-on-startup>
   </servlet>

 2.添加rar,iso等的mime-type映射避免在浏览器里直接打开。
<mime-mapping>
<extension>mht</extension>
<mime-type>text/x-mht</mime-type>
</mime-mapping>
<mime-mapping>
       <extension>rar</extension>
       <mime-type>application/octet-stream</mime-type>
   </mime-mapping>
   <mime-mapping>
       <extension>iso</extension>
       <mime-type>application/octet-stream</mime-type>
   </mime-mapping>
   <mime-mapping>
       <extension>ape</extension>
       <mime-type>application/octet-stream</mime-type>
   </mime-mapping>
   <mime-mapping>
       <extension>rmvb</extension>
       <mime-type>application/octet-stream</mime-type>
   </mime-mapping>
   <mime-mapping>
       <extension>ico</extension>
       <mime-type>image/x-icon</mime-type>
   </mime-mapping>

  <mime-mapping>
  <extension>doc</extension> 
<mime-type>application/msword</mime-type> 
</mime-mapping> 
<mime-mapping> 
  <extension>xls</extension> 
  <mime-type>application/vnd.ms-excel</mime-type> 
</mime-mapping> 
<mime-mapping> 
  <extension>ppt</extension> 
  <mime-type>application/vnd.ms-powerpoint</mime-type> 
</mime-mapping>

3.对html静态页面设置编码

<!--  修改下面两行以支持静态超文本的自动编码
  -->
 <mime-mapping>
 <extension>htm</extension>
 <mime-type>text/html;charset=gb2312</mime-type>
 </mime-mapping>
 <mime-mapping>
 <extension>html</extension>
 <mime-type>text/html;charset=gb2312</mime-type>
 </mime-mapping>
  </web-app>

展开阅读全文

没有更多推荐了,返回首页