第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

中文用戶名在保存時(shí)亂碼……

=-=代碼基本和老師給的相同,只不過(guò)我在登陸的時(shí)候加了一個(gè)密碼的驗(yàn)證。登陸成功后,發(fā)現(xiàn)查看用戶信息時(shí)的中文用戶名是亂碼狀態(tài)。我覺(jué)得應(yīng)該是將用戶名保存進(jìn)cookie時(shí)出現(xiàn)了亂碼,但存入cookie的方法是老師說(shuō)的那種。主要代碼貼出,請(qǐng)指教

這是dologin.jsp的內(nèi)容

<%@?page?language="java"?import="java.util.*"?contentType="text/html;?charset=utf-8"?pageEncoding="utf-8"%>
<%@?page?import="java.net.*"?%>
<jsp:useBean?id="loginUser"?class="com.po.Users"?scope="page"/>
<jsp:useBean?id="userDAO"?class="com.dao.UsersDAO"?scope="page"/>
<jsp:setProperty?name="loginUser"?property="*"/>
<%
String?path?=?request.getContextPath();
String?basePath?=?request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE?HTML?PUBLIC?"-//W3C//DTD?HTML?4.01?Transitional//EN">
<html>
??<head>
????<base?href="<%=basePath%>">
????
????<title>My?JSP?'dologin.jsp'?starting?page</title>
????
	<meta?http-equiv="pragma"?content="no-cache">
	<meta?http-equiv="cache-control"?content="no-cache">
	<meta?http-equiv="expires"?content="0">????
	<meta?http-equiv="keywords"?content="keyword1,keyword2,keyword3">
	<meta?http-equiv="description"?content="This?is?my?page">
	<!--
	<link?rel="stylesheet"?type="text/css"?href="styles.css">
	-->

??</head>
??
??<body>
????<h1>登錄判斷</h1>
????<%
????	response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
	
		String[]?isUseCookie?=?request.getParameterValues("isUseCookie");
	
		if(userDAO.usersLogin(loginUser))
		{
		
			if(isUseCookie?!=null?&&?isUseCookie.length>0)
			{
		??		String?username?=?URLEncoder.encode(request.getParameter("username"),"utf-8");
??????????		//使用URLEncoder解決無(wú)法在Cookie當(dāng)中保存中文字符串問(wèn)題
??????????		String?password?=?URLEncoder.encode(request.getParameter("password"),"utf-8");
??????????
??????????		Cookie?usernameCookie?=?new?Cookie("username",username);
??????????		Cookie?passwordCookie?=?new?Cookie("password",password);
	????????	usernameCookie.setMaxAge(864000);
	????????	passwordCookie.setMaxAge(864000);//設(shè)置最大生存期限為10天
	????????	response.addCookie(usernameCookie);
	????????	response.addCookie(passwordCookie);
			}
			else
			{
				Cookie[]?cookies?=?request.getCookies();
				if(cookies!=null?&&?cookies.length>0)
				{
					for(Cookie?c:cookies)
					{
						if(c.getName().equals("username")?||?c.getName().equals("password"))
						{
							c.setMaxAge(0);
							response.addCookie(c);
						}
					}
				}
			}
			request.getRequestDispatcher("login_success.jsp").forward(request,?response);
		}
		else
		{
			response.sendRedirect("login_failure.jsp");
		}
????%>
??</body>
</html>

login.jsp和user.jsp的內(nèi)容與老師給的是一樣的


正在回答

4 回答

修改server.xml文檔,在Connector標(biāo)簽里面添加URIEncoding="utf-8"應(yīng)該能夠解決

0 回復(fù) 有任何疑惑可以回復(fù)我~

跟你一樣,原來(lái)的樣例直接拷貝,結(jié)果上面這三行沒(méi)刪:

<jsp:useBean?id="loginUser"?class="com.po.Users"?scope="page"/>
<jsp:useBean?id="userDAO"?class="com.dao.UsersDAO"?scope="page"/>
<jsp:setProperty?name="loginUser"?property="*"/>

就造成一直亂碼,懷疑是javaBeans做處理時(shí),更改了編碼。

猜想因?yàn)榍懊姹韱沃械膗sername password,正好被上面配置的javabean給自動(dòng)匹配上了。所以這個(gè)階段處理時(shí),編碼發(fā)生了轉(zhuǎn)換。

0 回復(fù) 有任何疑惑可以回復(fù)我~

=-=使用復(fù)制粘貼不斷進(jìn)行對(duì)比后,發(fā)現(xiàn)問(wèn)題竟然是出在

<jsp:useBean?id="loginUser"?class="com.po.Users"?scope="page"/>

<jsp:useBean?id="userDAO"?class="com.dao.UsersDAO"?scope="page"/>

<jsp:setProperty?name="loginUser"?property="*"/>

這段聲明中,若是把這段代碼刪去,編碼就沒(méi)有問(wèn)題。這是何等奇葩的現(xiàn)象,真心求解……

0 回復(fù) 有任何疑惑可以回復(fù)我~

你數(shù)據(jù)庫(kù)編碼對(duì)不對(duì)

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

sioneden 提問(wèn)者

數(shù)據(jù)庫(kù)編碼?請(qǐng)問(wèn)具體是哪部分?
2015-03-12 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

中文用戶名在保存時(shí)亂碼……

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)