问题描述
login.jsp中的代码:<%@pagelanguage="java"import="java.util.*"pageEncoding="utf-8"%><%Stringpath=request.getContextPath();StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head><basehref="<%=basePath%>"><title>MyJSP'login.jsp'startingpage</title><script>functioncheckdata(){name=document.fm.name.value;password=document.fm.password.value;if(name==""){alert("用户名不能为空!");fm.name.focus();returnfalse;}if(password==""){alert("密码不能为空!")fm.password.focus();returnfalse;}if(password==""||password.length!=6||isNaN(password)){alert("密码要6位的数字");fm.password.focus();returnfalse;}if(name.length<3||name.length>8){alert("用户名长度必须在3位到8位之间");fm.name.focus();returnfalse;}returntrue;}</script></head><bodybackground="image/Sunset.jpg"><formaction="welcome.jsp"method="post"name="fm"OnSubmit="returncheckdata();"><tablealign="center"><tr><th>用户登录界面</th></tr><tr><td>用户名:<inputtype="text"name="name">(3-8位)</td></tr><tr><td>密 码:<inputtype="password"name="password">(6位的数字字符)</td></tr><tr><td> <inputtype="submit"value="提交"name="boy"></td></tr></table></form></body></html>welcome.jsp中的代码:<%@pagelanguage="java"import="java.util.*"pageEncoding="utf-8"%><%Stringpath=request.getContextPath();StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head><basehref="<%=basePath%>"><title>MyJSP'welcome.jsp'startingpage</title><metahttp-equiv="pragma"content="no-cache"><metahttp-equiv="cache-control"content="no-cache"><metahttp-equiv="expires"content="0"><metahttp-equiv="keywords"content="keyword1,keyword2,keyword3"><metahttp-equiv="description"content="Thisismypage"><!--<linkrel="stylesheet"type="text/css"href="styles.css">--></head><body><%Stringusername="张三李",password1="123456";Stringname=newString(request.getParameter("name").getBytes("iso-8859-1"));Stringpassword=newString(request.getParameter("password").getBytes("iso-8859-1"));session.setAttribute("name",name);session.setAttribute("paaword",password);if(name.equals(username)&&password.equals(password1)){out.println("欢迎你,"+name);out.println("你输入的密码是:"+password);}else{%><script>alert("用户名或密码输入错误,请重新输入");history.back();</script><%}%></body></html>
解决方案
解决方案二:
中文请注意转码:Stringname=newString(request.getParameter("name").getBytes("ISO-8859-1"),"utf-8");Stringpassword=newString(request.getParameter("password").getBytes("iso-8859-1"),"utf-8");
你怎么发了两次。。
解决方案三:
引用1楼ylz2007的回复:
中文请注意转码:JavacodeStringname=newString(request.getParameter("name").getBytes("ISO-8859-1"),"utf-8");Stringpassword=newString(request.getParameter("password")……
正解啊
解决方案四:
试试1楼的
解决方案五:
恩,,试试1楼的