我现在编一个JSP页面,整个页面分三部分,头、中间和尾,头和尾用<%@include file="top.html"%>、<%@include file="bottom.html"%>引入进来,但在浏览器中显示时头和尾出现乱码,而中间正常,若单独显示top.html和bottom.html则没有乱码,真是不明白怎么回事,请大家指教,谢谢!!

解决方案 »

  1.   

    是不是你的JSP页面和你引入的HTML页面的编码方式不一样呀
      

  2.   

    这是我的代码 
    JSP页面de
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
    <%String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
    + request.getServerName() + ":" + request.getServerPort()
    + path + "/";
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <base href="<%=basePath%>"> <title>欢迎访问可控环境农业实验实网站!</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">
    <style TYPE="text/css">
    <!--
    A:link{text-decoration:none}
    A:visited{text-decoration:none}
    A:hover {color: #ff00ff;text-decoration:underline}
    -->
    </style> </head><body>
    <FONT size="2"><%@include file="top.html"%></FONT> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT style="BACKGROUND-COLOR: #ffffff"> </FONT>
    <a link href="index.jsp" target="_self" ><FONT size="2" style="BACKGROUND-COLOR: #ffffff" color="#000000">首页</FONT></a>  &nbsp;&nbsp;&nbsp;<a link href="introduction.jsp" target="_self" ><FONT size="2" style="BACKGROUND-COLOR: #ffffff" color="#000000">实验室简介</FONT></a>  &nbsp;&nbsp;&nbsp;<a link href="introduction.jsp" target="_self" ><FONT size="2" style="BACKGROUND-COLOR: #ffffff" color="#000000">基础设施</FONT></a>  &nbsp;&nbsp;&nbsp;<a link href="introduction.jsp" target="_self" ><FONT size="2" style="BACKGROUND-COLOR: #ffffff" color="#000000">科研队伍</FONT></a>  &nbsp;&nbsp;&nbsp;<a link href="introduction.jsp" target="_self" ><FONT size="2" style="BACKGROUND-COLOR: #ffffff" color="#000000">研究项目</FONT></a>  &nbsp;&nbsp;&nbsp;<a link href="introduction.jsp" target="_self" ><FONT size="2" style="BACKGROUND-COLOR: #ffffff" color="#000000">论文专著</FONT></a>  &nbsp;&nbsp;&nbsp;<a link href="introduction.jsp" target="_self" ><FONT size="2" style="BACKGROUND-COLOR: #ffffff" color="#000000">成果展示</FONT></a>  &nbsp;&nbsp;&nbsp;<a link href="introduction.jsp" target="_self" ><FONT size="2" style="BACKGROUND-COLOR: #ffffff" color="#000000">招生招聘</FONT></a>  &nbsp;&nbsp;&nbsp;<a link href="introduction.jsp" target="_self" ><FONT size="2" style="BACKGROUND-COLOR: #ffffff" color="#000000">会员专区</FONT></a>

    <TABLE align="center" border="1" width="700" height="600">
    <TR>
    <TD></TD>
    </TR>
    </TABLE>
    <%@ include file="bottom.html"%>
    </body>
    </html>
    top.html的
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <title>top.html</title>
        
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="this is my page">
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
        <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
        
      </head>
      
      <body>
    <P align="center">


    <TABLE align="center" border="1" bgcolor="#ffffff" width="700px" height="100px" background="" bordercolor="">
    <TR>
    <TD bgcolor="#209cdf">
    <P><IMG src="log.jpg" border="0" align="left"><FONT color="#ffffff"> &nbsp;<FONT color="#ffffff" size="5">中国农业科学院</FONT></FONT></P>
    <P>
    <FONT color="#ffffff" size="6"><marquee>kkk可控环境农业实验室</marquee></FONT>
    </P>
    </TD>
    </TR>
    </TABLE>
    <FONT size="7"> </FONT>
    </P>
    </body>
    </html>
      

  3.   

    还有就是即使把top.html的编码方式改成UTF-8也还是乱码
      

  4.   

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
    这句写上也还是有乱码吗?
      

  5.   

    应用进来的页面最好不要有中文。因为包括进来的页面不能写这句话:<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>。tomcat的默认编码方式又是iso-8859-1的形式。
    所以这个乱码不好解决。
      

  6.   

    提个建议啊,把top.html 改成top.jsp ,让top.jsp的编码和你的这个jsp页面的编码一样,
    这样就可以了啊.
      

  7.   

    我把<%@include file="top.html"%>改成了<jsp:include page="top.html"/>,这样在页面显示时上部就不乱码了,嘿嘿!但是将botton用了同样的改法,却还是乱码,真是太奇怪了。我觉得这个问题应该很容易似的,哎!真是郁闷!大家快帮帮我啊!!
      

  8.   

    把<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
    改为
    <%@ page contentType="text/html; charset=UTF-8" %>
    <%@page import="java.util.*"%>并在top.jsp和bottom.jsp中加入
    <%@ page contentType="text/html; charset=UTF-8" %>你把top.html改为top.jsp,要不html中有可能不认<%@ page contentType="text/html; charset=UTF-8" %>
    要是还不行,你把UTF-8改为gb2312试试
      

  9.   

    真的改成top.jsp就行了 为什么呢????谢谢小群!!