分享

jsp:include 使用jsp:param乱码解决

 我的java之路 2016-10-04

 

如果jsp:include 中的page页面存在乱码 ,则需要在使用<jsp:include page=""> 的页面中的<body>后加上

<%

    request.setCharacterEncoding('UTF-8") ;//或者指定的编码(GBK或其他)

%>

如下面所示:

 

  1. jsp-include.jsp  
  2.   
  3. <%@ page language="java" contentType="text/html;charset=UTF-8" %>  
  4. <html>  
  5.  <head><title>jsp include测试页</title></head>  
  6.  <body>  
  7.  <%  
  8.   request.setCharacterEncoding("UTF-8") ;  
  9.  %>  
  10.  <h3>jsp include 指令测试</h3>  
  11.    
  12.  <jsp:include page="forward-result.jsp">  
  13.   <jsp:param name="age" value="32" />  
  14.   <jsp:param name="username" value="张三" />  
  15.  </jsp:include>  
  16.     
  17.  </body>  
  18. </html>  
  19.   
  20.   
  21.   
  22. forward-result.jsp  
  23.   
  24. <%@ page language="java" contentType="text/html;charset=UTF-8" %>  
  25. <html>  
  26.  <head><title>forward的结果页</title></head>  
  27.  <body>  
  28.   
  29.   年龄:<%=request.getParameter("age")%><br />  
  30.   姓名:<%=request.getParameter("username") +"--11"%>  
  31.     
  32.  </body>  
  33. </html>  


  

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多