JSP中比较变量的值
<body><%Stringmyanswer=request.getParameter("answer").toString();StringlibraryNum=ses...
<body>
<%String myanswer= request.getParameter("answer").toString();
String libraryNum= session.getAttribute("libraryNum").toString();
session.setAttribute("libraryNum",libraryNum);
System.out.println(myanswer);
System.out.println(libraryNum);
DB db=new DB();
String sql="select * from userInfo where libraryNum='"+libraryNum+"'";
ResultSet rs=db.executeQuery(sql);
answer answer=new answer();
if(rs.next())
{
answer.setAnswer(rs.getString(10));
String realanswer=answer.getAnswer().toString();
if(!(myanswer.equals("realanswer")))
{
System.out.println("验证成功!");
response.setHeader("Refresh","2;URL=renew.jsp");
}
System.out.println("realanswer:"+realanswer);
System.out.println("myanswer:"+myanswer);
System.out.println(myanswer.equals(realanswer));
%>
</body>
System.out.println("realanswer:"+realanswer); //打印出realanswer的值
System.out.println("myanswer:"+myanswer); //打印出myanswer的值
System.out.println(myanswer.equals(realanswer));
为什么打印出的realanswer和myanswer一样但是下面的 myanswer.equals(realanswer)任然为false呢? 展开
<%String myanswer= request.getParameter("answer").toString();
String libraryNum= session.getAttribute("libraryNum").toString();
session.setAttribute("libraryNum",libraryNum);
System.out.println(myanswer);
System.out.println(libraryNum);
DB db=new DB();
String sql="select * from userInfo where libraryNum='"+libraryNum+"'";
ResultSet rs=db.executeQuery(sql);
answer answer=new answer();
if(rs.next())
{
answer.setAnswer(rs.getString(10));
String realanswer=answer.getAnswer().toString();
if(!(myanswer.equals("realanswer")))
{
System.out.println("验证成功!");
response.setHeader("Refresh","2;URL=renew.jsp");
}
System.out.println("realanswer:"+realanswer);
System.out.println("myanswer:"+myanswer);
System.out.println(myanswer.equals(realanswer));
%>
</body>
System.out.println("realanswer:"+realanswer); //打印出realanswer的值
System.out.println("myanswer:"+myanswer); //打印出myanswer的值
System.out.println(myanswer.equals(realanswer));
为什么打印出的realanswer和myanswer一样但是下面的 myanswer.equals(realanswer)任然为false呢? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询