如果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>