String username = request.getParameter("username");
String userpsw = request.getParameter("userpsw");
System.out.println("name " + username);
System.out.println("psw " + userpsw);
session.setAttribute("name", username);
session.setAttribute("psw", userpsw); if (username.equals("我") && userpsw.equals("123")) { response.sendRedirect("showname.jsp");
} else {
response.sendRedirect("show1.jsp");
}
如果username.equals("我")中把我改成"aa"就可以跳到showname.jsp页面
不改就跳到show1.jsp页面,获取username时为问号。
String userpsw = request.getParameter("userpsw");
System.out.println("name " + username);
System.out.println("psw " + userpsw);
session.setAttribute("name", username);
session.setAttribute("psw", userpsw); if (username.equals("我") && userpsw.equals("123")) { response.sendRedirect("showname.jsp");
} else {
response.sendRedirect("show1.jsp");
}
如果username.equals("我")中把我改成"aa"就可以跳到showname.jsp页面
不改就跳到show1.jsp页面,获取username时为问号。
http://www2.matrix.org.cn/resource/article/2005-04-11/1428.html
很麻烦 应该和“url含中文”一样的
String new=new String(temper,"gb2312");
转码也不行吗?我自己没试试过
当数据库里面的用户名为 我的时候
System.out.println("name " + username);
的输出也为 我 吗?
username.equals("我");
这一句的本身是没问题的,,可能是你数据库里面存储的数据的问题,,
例如,,你在 界面上输入了“我”但由于你的字符编码没设好,,导致插入到数据库里面的是“????”了
或者你没进行空格的过滤,,输入的“我 ”,注意我后面多了个空格,,导致插入数据库的为“我 ”了,,
而你再拿"我 “和”我“比较,当然不可以了
建议你到数据库里看看存储的内容把
if(username.equals(a));
一、数据库用的如果是char字段,那么数据库存储的时候,如果不够位数,后面会自动空格补齐。解决办法:1、将数据库改成varchar,或者用从数据库中拿出来后去掉空余字符。
二、编码的问题:
在jsp中:
value='<%=new String(request.getParameter("name").getBytes("ISO-8859-1"),"gb2312")%>'试试
不行,你试试用其他编码方式,把gb2312改成utf-8等等
1,沒有亂碼 ok
2,有亂碼 轉碼,如果是post請求 request.setCharacterEncoding("ISO8859-1");這裡可以是其他編碼
如果是get請求,只能是new String("xxx").getBytes("ISO-8859-1"),或者修改tomcat的配置文件。