亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

中文亂碼問題(請問為啥為設置了字符編碼為utf-8,但是username的時候還是亂碼了)

<%@ page language="java" import="java.net.*,java.util.*" contentType="text/html; charset=utf-8"

? ? pageEncoding="utf-8"%>

<!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>主頁</title>

</head>

<body>

<h1>用戶登錄</h1>

<hr>

<%

request.setCharacterEncoding("utf-8");

String username="";

String password="";

Cookie[] cookies = request.getCookies();

if(cookies != null && cookies.length > 0){

for(Cookie cookie:cookies){

if(cookie.getName().equals("username")){

username = URLEncoder.encode(cookie.getValue(),"utf-8");

}

if(cookie.getName().equals("password")){

password = URLEncoder.encode(cookie.getValue(),"utf-8");

}

}

}



%>

<form name="loginForm" action="dologin.jsp" method="post">

<table>

<tr>

<td>用戶名:</td>

<td><input type="text" name="username" value="<%=username %>"></td>

</tr>

<tr>

<td>密碼:</td>

<td><input type="password" name="password" value="<%=password%>"></td>

</tr>

<tr>

<td colspan="2"><input type="checkbox" name="remenber" checked="checked"/>記住密碼</td>

</tr>

<tr>

<td colspan="2" align="center"><input type="submit" value="登錄"></td>

</tr>

</table>

</form>

</html>


正在回答

3 回答

username = URLEncoder.encode(cookie.getValue(),"utf-8"); ??

試一下username = URLDecoder.decode(cookie.getValue(),'utf-8');

0 回復 有任何疑惑可以回復我~
#1

Zhao_Tenfe 提問者

謝謝,不過還是亂碼,一樣的
2016-11-17 回復 有任何疑惑可以回復我~
#2

Zhao_Tenfe 提問者

非常感謝!是這個原因
2016-11-17 回復 有任何疑惑可以回復我~

我的也是 ,你怎么解決的

0 回復 有任何疑惑可以回復我~
#1

Zhao_Tenfe 提問者

username = URLEncoder.encode(cookie.getValue(),"utf-8"); 試一下username = URLDecoder.decode(cookie.getValue(),'utf-8');
2016-11-19 回復 有任何疑惑可以回復我~

沒事的

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

中文亂碼問題(請問為啥為設置了字符編碼為utf-8,但是username的時候還是亂碼了)

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號