jsp页面中使用include标签进行包含其他页面:
index.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" 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> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <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"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> 哈哈 <jsp:include page="header.html" flush="true"></jsp:include> </body> </html>
header.jsp:
<!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> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> </head> <body> 中华人民共和国 </body> </html>
直接访问header.jsp的时候页面显示正常,但是访问index.jsp的时候 index中的文字显示正常,而被包含的header中的文字却都是中文乱码。
而我们已经把编码都设置统一的UTF-8了,还是会出现乱码。
解决办法:
1、把所有的页面的编码全都改成中文的GBK编码,可以正常。
2、所有的页面,不论是静态的还是动态的,全都用jsp文件写,即把.html改成.jsp即可。
3、
在项目的web.xml里面放入这串代码就可以了:
<!-- 控制jsp:include的编码 --> <jsp-config> <jsp-property-group> <description> Special property group for JSP Configuration HTML 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>
相关推荐
动态Jsp页面转换成静态Html页面动态Jsp页面转换成静态Html页面动态Jsp页面转换成静态Html页面动态Jsp页面转换成静态Html页面动态Jsp页面转换成静态Html页面动态Jsp页面转换成静态Html页面动态Jsp页面转换成静态Html...
jsp include 乱码问题的解决方法! 希望能够解决你的问题!
解决jsp页面乱码,页面信息配置,tomcat配置以及各种信息配置
jsp页面传值中文乱码问题处理.docx
如何解决JSP页面显示乱码问题
JSP页面上出现中文乱码的几个解决办法 比较好的 一般都能解决问题
jsp页面跳转到后台乱码 还需要在html中指定编码格式。 <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>title 解决方法是要在jsp最前面加上一条java语句,设置请求的字符编码。...
Struts2资源文件在jsp页面中显示乱码解决
NULL 博文链接:https://prowl.iteye.com/blog/483854
大家在JSP的开发过程中,经常出现中文乱码的问题,可能一至困扰着大家,现把JSP开发中遇到的中文乱码的问题及解决办法写出来供大家参考。
动态INCLUDE 用法:<jsp page=”included.jsp” flush=”true”> 说明:它总是会检查所含文件中的变化,适合用于包含动态页面,并且可以带参数,先编译之后再进行处理。 原因:1、静态include的结果是把其他jsp引入...
用jsp:include动作实现 <jsp include page=”included.jsp” flush>它总是会检查所含文件中的变化,适合用于包含动态页面,并且可以带参数。 静态INCLUDE 用include伪码实现,定不会检查所含文件的变化,...
JSP中文问题解决办法,JSP页面传值,数据库等的中文乱码解决办法
对常见中文乱码问题进行了详细介绍和解释,希望能给大家以帮助。
jsp中文乱码的处理 页面显示 表单提交 数据库操作JSP中文乱码处理
jsp页面显示中文乱码解决.rar
主要介绍了JSP页面传参出现中文乱码的解决方案,非常实用,需要的朋友可以参考下
JSP中文乱码
在JSP输出的基础上将标签内的内容保存成静态文件,下次及可以直接调用