zl程序教程

您现在的位置是:首页 >  后端

当前栏目

基于jsp:included的使用与jsp:param乱码的解决方法

JSP方法 使用 解决 基于 乱码 param included
2023-06-13 09:15:00 时间
如果jsp:include中的page页面存在乱码,则需要在使用<jsp:includepage="">的页面中的<body>后加上
<%
   request.setCharacterEncoding("UTF-8");//或者指定的编码(GBK或其他)
%>
如下面所示:
复制代码代码如下:

jsp-include.jsp
<%@pagelanguage="java"contentType="text/html;charset=UTF-8"%>
<html>
 <head><title>jspinclude测试页</title></head>
 <body>
 <%
 request.setCharacterEncoding("UTF-8");
 %>
 <h3>jspinclude指令测试</h3>

 <jsp:includepage="forward-result.jsp">
 <jsp:paramname="age"value="32"/>
 <jsp:paramname="username"value="张三"/>
 </jsp:include>

 </body>
</html>
forward-result.jsp
<%@pagelanguage="java"contentType="text/html;charset=UTF-8"%>
<html>
 <head><title>forward的结果页</title></head>
 <body>
 年龄:<%=request.getParameter("age")%><br/>
 姓名:<%=request.getParameter("username")+"--11"%>

 </body>
</html>