<转> jsp:include 乱码问题解决

 jsp include页面出现乱码问题的几种通用解决方法:


1.当jsp include动态文件时(jsp文件)可以在被include的jsp文件头部加上代码:

<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>

2.当jsp include静态文件时(html文件)可以在被include的html文件的<head></head>标签内加上代码:

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

3.当jsp include不能够修改的文件时(比如HTML片段等)可以修改tomcat的web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee  
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 
 
    <jsp-config> 
        <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> 
 
            <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-config> 
 
</web-app>

      Tomcat 5之后,支持了 JSP 2.0 的规格,同时也支持了部分 J2EE 1.4 的规范,在 J2EE 1.4 的规范中,有关 JSP 的部份,有一个 <jsp-config>;的 XML Tag,这个 XML 区块用来定义与 JSP 相关的特殊属性。

    <el-ignored>               若为true,表示不支持EL语法
    <page-encoding>            若为true,表示不支持<% scripting %>语法
    <scripting-invalid>        设置页面编码
    <include-prelude>          设置页面抬头,扩展名为.jspf
    <include-coda>             设置页面结尾,扩展名为.jspf

      在一个编码为utf-8的页面中,使用<jsp:include>包含另一个.jsp/.html文件时,被包含的页面单独浏览正常,但被包含后就会遇到乱码问题。解决的办法是,在每个被包含的页面开始加上下面一行<% page contentType=&quot;text/html;charset=utf-8&quot; %>这个方法可以解决jsp include jsp的中文乱码问题。也就是说,被包含的页面必须改成.jsp,哪怕它的内容只有静态html,否则的话还是会出现乱码。

      PS:本人所遇到的问题使用方法三解决

 

转载于:https://www.cnblogs.com/tq03/p/3593748.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
请解释以下代码<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>注册第一步</title> </head> <body> <% // 设置请求编码方式,防止中文乱码问题 request.setCharacterEncoding("UTF-8"); %> <!-- 查找JavaBean对象,使用请求参数为对象属性赋值 --> <jsp:useBean id="user" class="com.test.chapter07.javabean.UserBean" scope="session" /> <jsp:setProperty property="*" name="user" /> <h2 align="center">用户注册信息确认</h2> <form action="registerSuccess.jsp" method="post"> <table border="1" width="50%" align="center"> <tr> <td>用户名:</td> <td><jsp:getProperty property="username" name="user" /></td> </tr> <tr> <td>密 码:</td> <td><jsp:getProperty property="password" name="user" /></td> </tr> <tr> <td>性别:</td> <td><jsp:getProperty property="sex" name="user" /></td> </tr> <tr> <td>年龄:</td> <td><jsp:getProperty property="age" name="user" /></td> </tr> <tr> <td>提示信息:</td> <td><jsp:getProperty property="tooltip" name="user" /></td> </tr> <tr> <td>提示答案:</td> <td><jsp:getProperty property="answer" name="user" /></td> </tr> <tr> <td>邮箱:</td> <td><jsp:getProperty property="email" name="user" /></td> </tr> <tr> <td>愿意接受信息:</td> <td><jsp:getProperty property="messageChoose" name="user" /></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="确认提交"></td> </tr> </table> </form> </body> </html>
05-25

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值