刚学servlet求帮助

阿力水手-Ally 2012-08-20 04:58:03
小弟遇到个问题,以下为代码,问题在最后。
String u=req.getParameter("stuName");
String p=req.getParameter("password");
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
ct=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=stu","sa","yuanrunli");
sm=ct.createStatement();
rs=sm.executeQuery("select top 1 password from student where stuName='"+u+"'");
//判断是否有该用户名
if(rs.next())
{

String dbpassword=rs.getString(1);
System.out.println(dbpassword);---------------------------------1
System.out.println(p);-------------------------------------2
if(p.equals(dbpassword))
{
//合法用户跳转到登入成功页面
System.out.println(dbpassword);
System.out.println(p);
resp.sendRedirect("login3");
}

}
else
//不合法跳转到登入页面
{

resp.sendRedirect("login1");
}
以上为代码,测试能得到1的dbpassword和p的值,都是admin,可是为什么没进入下面的相等判断呢?
...全文
43 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
阿力水手-Ally 2012-08-20
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

用中文登录不成功属于编码问题了。。。

页面跳到servlet后
Java code

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("gb2312……
[/Quote]谢谢。OK了
streamcc 2012-08-20
  • 打赏
  • 举报
回复
用中文登录不成功属于编码问题了。。。

页面跳到servlet后

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("gb2312");
......
response.setContentType("text/html;charset=gb2312");
response.sendRedirect ( "XXXX.jsp" );
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
阿力水手-Ally 2012-08-20
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

检查空格
[/Quote]是空格问题,谢谢,不过我用中文的用户名登陆还是不能,请问是什么原因?
jackson_fighting 2012-08-20
  • 打赏
  • 举报
回复
检查空格

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧