zoukankan      html  css  js  c++  java
  • JSP学习笔记—— jsp中include文件指令乱码的三种解决方案

    这几天写学习JSP的过程中遇到了一个小问题——include html文件的时候出现乱码。

    谷歌了一下,有的说 include静态文件时(html文件)可以在被include的html文件的<head></head>标签内加上代码: 

      <meta http-equiv="Content-Type" content="text/html; charset=GB2312" />

    但是这种方法似乎并不可行,所以有找到了其他几种比较好的方法。

      1.无论是include jsp动态文件,还是html静态文件,在文件头添加

    1 <%@page contentType="text/html;charset=gb2312"%> 

      可以解决。

      2.将html静态文件改为jsp动态文件,并在文件头添加 

    1 <%@page contentType="text/html;charset=gb2312"%> 

      方法和第一种类似,可以解决。

      3.修改WEB-INF文件中的web.xml文件,在<web-app>标签中嵌套如下代码:

    <jsp-config>
             <jsp-property-group>
                 <description>
                     Special property group for JSP Configuration JSP
                     example.
                 </description>
                 <display-name>JSPConfiguration</display-name>
                 <url-pattern>*.html</url-pattern>
                <el-ignored>true</el-ignored>
                 <page-encoding>UTF-8</page-encoding>
                 <scripting-invalid>false</scripting-invalid>
                 <include-prelude></include-prelude>
                 <include-coda></include-coda>
             </jsp-property-group>
       <jsp-property-group>
            
                    <description>
                      Special property group for JSP Configuration JSP
                      example.
                  </description>
                  <display-name>JSPConfiguration</display-name>
                 <url-pattern>*.jsp</url-pattern>
                 <el-ignored>true</el-ignored>
                 <page-encoding>UTF-8</page-encoding>
                 <scripting-invalid>false</scripting-invalid>
                 <include-prelude></include-prelude>
                 <include-coda></include-coda>
    
       </jsp-property-group>
         </jsp-config>        

      同样可以解决,需要注意的是:<web-app>标签的version属性一定要为2.4或以上。

       上面配置需要的一些标签的含义如下:

      

    <jsp-config> 包括<taglib> 和<jsp-property-group> 两个子元素。

    <taglib>元素在JSP 1.2 时就已经存在;
    <jsp-property-group>是JSP 2.0 新增的元素:
    <jsp-property-group>元素主要有八个子元素,它们分别为:
    <description>:设定的说明;
    <display-name>:设定名称;
    <url-pattern>:设定值所影响的范围,如: /*.jsp;
    <el-ignored>:若为true,表示不支持EL 语法;
    <scripting-invalid>:若为true,表示不支持<% scripting %>语法;
    <page-encoding>:设定JSP 网页的编码;
    <include-prelude>:设置JSP 网页的抬头,扩展名为.jsp
    <include-coda>:设置JSP 网页的结尾,扩展名为.jsp

    参考资料:http://www.wenhq.com/article/view_376.html

  • 相关阅读:
    让div 充满整个body GIS
    fortuneclient 学习 (客户端接受数据) GIS
    错误 1 error C1083: 无法打开包括文件:“QNetworkProxy”: No such file or directory GIS
    qt fortuneserver 例子学习 ( 给客户端发送消息) GIS
    new操作符(new operator) 和 new操作(operator new)的区别。 GIS
    qt 控件 GIS
    c++ 顺序容器 GIS
    将一个div 分成两列 也可以分成多列 GIS
    控件模板 1
    WPF简单写写。。。
  • 原文地址:https://www.cnblogs.com/iridescent/p/2620587.html
Copyright © 2011-2022 走看看