[学习笔记]jsp中超级链接 中文编码处理

超级链接传递中文 编码问题

[1]对于
<%
String param="我是我";
%>
 由<a href=as.jsp?param=<%=param%>>nihao</a>
 传递的中文问题,可以采取在本页面 showpt.jsp 和接收参数的as.jsp页面顶头添加
<%@ page contentType="text/html; charset=GBK" %>
并用
 String param= new String(request.getParameter("param").getBytes("ISO-8859-1"), "GBK");
来接收
则会发现,在as.jsp页面的地址栏中出现的是as.jsp?param=我是我
页面也能正确的接收。


[2]表单 method="get" 方法的处理方式 也是如此

 

//showpt.jsp
<% -- 
    Document   : showpt
    Created 
on : 2008-4-2319:22:45
    Author     : a60
--
%>



<% @ page contentType="text/html; charset=gbk"  %>
<! 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 > JSP Page </ title >
    
</ head >
    
< body >
 
        
<%
        
String param="我是我";

        
%>
        
       
< href =as.jsp?param=<%=param% > >nihao </ a >
       
           
< form  action ="as.jsp"  method ="get" >
            标题:
< input  type ="text"   name ="param"  value ="" >
            
                 
< input  type ="submit"  name  ="submit" value ="提交"   >
           
</ form >
      
  
        
    
</ body >
</ html >

 

 

 

//as.jsp
<% -- 
    Document   : 
as.jsp
    Created 
on : 2008-4-2319:30:43
    Author     : a60
--
%>



<% @ page contentType="text/html; charset=GBK"  %>
<! 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 > JSP Page </ title >
    
</ head >
    
< body >
        
        
< h2 > sssss </ h2 >
        
<%
 
String param= new String(request.getParameter("param").getBytes("ISO-8859-1"), "GBK");
     

if(param!=null){
        out.println(param);
        
%>
        
< href ="index.jsp?param=<%=param%>" > heheh </ a >
        
        
<%
        }
        
//String cont=request.getParameter("cont");
       
// out.println(cont);
       
else{
       out.println();
       }
        
%>
    
</ body >
</ html >

 

 

//index.jsp
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd"
>
<% @ page contentType="text/html; charset=GBK"  %>
< html >
    
< head >
        
< meta  http-equiv ="Content-Type"  content ="text/html; charset=UTF-8" >
        
< title > JSP Page </ title >
    
</ head >
    
< body >
  
<%

      
String param= new String(request.getParameter("param").getBytes("ISO-8859-1"), "GBK");

if(param!=null){
        out.println(param);
        }
   
%>
        
< h2 > Hello World! </ h2 >
    
</ body >
</ html >
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值