向jsp页面传值时出现乱码

在一个html页面中用表单向jsp页面传值:

这是html页面

<html>
  <head>
    <title>MyBeans.html</title>
    
    <meta name="keywords" content="keyword1,keyword2,keyword3">
    <meta name="description" content="this is my page">
    <meta name="content-type" content="text/html; charset=UTF-8">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

  </head>
  
  <body>
  <form method="post" action="../jsp/MyBeans.jsp">
      学号:<input name="sno" type="text">
      姓名:<input name="name" type="text">
  <input value="submit" type="submit"> <input value="reset" type="reset">
  </form>
    This is my HTML page. <br>
  </body>
</html>

这是jsp页面中的解码:

<%String name=new String(request.getParameter("name").getBytes("ISO-8859-1"),"UTF-8"); %>
    <%System.out.println("name"+name); %>

这里注意:

<%String name=new String(request.getParameter("name").getBytes("A"),"B"); %>
A要为ISO-8859-1

B可以是自己决定的编码格式:为<meta http-equiv="content-type" content="text/html; charset=utf-8"> 中的charset的值。http-equiv的content-type的作用是设定页面使用的字符集。(个人猜测是html会将发送的内容先编码为B格式,再发送到服务器,jsp的接受数据的编码是ISO-8859-1,所以先要用ISO-8859-1解码,再用B格式转化为原来的数据)

 

转载于:https://www.cnblogs.com/l1019/p/6728404.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值