基于jsp:included的使用与jsp:param乱码的解决方法
程序员文章站
2023-11-04 20:55:28
如果jsp:include 中的page页面存在乱码,则需要在使用 的页面中的后加上<%...
如果jsp:include 中的page页面存在乱码,则需要在使用<jsp:include page=""> 的页面中的<body>后加上
<%
request.setcharacterencoding('utf-8") ;//或者指定的编码(gbk或其他)
%>
如下面所示:
jsp-include.jsp
<%@ page language="java" contenttype="text/html;charset=utf-8" %>
<html>
<head><title>jsp include测试页</title></head>
<body>
<%
request.setcharacterencoding("utf-8") ;
%>
<h3>jsp include 指令测试</h3>
<jsp:include page="forward-result.jsp">
<jsp:param name="age" value="32" />
<jsp:param name="username" value="张三" />
</jsp:include>
</body>
</html>
forward-result.jsp
<%@ page language="java" contenttype="text/html;charset=utf-8" %>
<html>
<head><title>forward的结果页</title></head>
<body>
年龄:<%=request.getparameter("age")%><br />
姓名:<%=request.getparameter("username") +"--11"%>
</body>
</html>
<%
request.setcharacterencoding('utf-8") ;//或者指定的编码(gbk或其他)
%>
如下面所示:
复制代码 代码如下:
jsp-include.jsp
<%@ page language="java" contenttype="text/html;charset=utf-8" %>
<html>
<head><title>jsp include测试页</title></head>
<body>
<%
request.setcharacterencoding("utf-8") ;
%>
<h3>jsp include 指令测试</h3>
<jsp:include page="forward-result.jsp">
<jsp:param name="age" value="32" />
<jsp:param name="username" value="张三" />
</jsp:include>
</body>
</html>
forward-result.jsp
<%@ page language="java" contenttype="text/html;charset=utf-8" %>
<html>
<head><title>forward的结果页</title></head>
<body>
年龄:<%=request.getparameter("age")%><br />
姓名:<%=request.getparameter("username") +"--11"%>
</body>
</html>
上一篇: Java String创建对象实例解析