• Post Reply Bookmark Topic Watch Topic
  • New Topic

if else

 
Leonardo Pjetri
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%@page language="java" %>


<HTML>
<BODY>
Hello! Enter stuff and press Log in
<FORM METHOD="POST" ACTION="test.jsp">
<TABLE>
<TR><TD>User name: <INPUT TYPE="TEXT" NAME="username">
<TR><TD> Password: <INPUT TYPE="PASSWORD" NAME="password">
<TR><TH><INPUT TYPE="SUBMIT" VALUE="Log In">
</TABLE>
</FORM>

</HTML>
</BODY>
-----------------------------------------------the login page---

<%@ page language="java" %>

<HTML>
<BODY>
Hello!

<%

String s1=request.getParameter("username");
String s2="leo";


if (s1==s2) {

out.println("<hr><font color=red>You got that right!\nSay again <h1> HA HA HA AH AHA AHAHAHAH AH HA </h1></font>");
}

else {
out.println("<h1> NO NO NO you are not leo </h1>");
out.println("<h1> NO NO NO you are not leo </h1>");
out.println("<h1> NO NO NO you are not leo </h1>"+s1);

}

%>
</HTML>
</BODY>
---------------------------------test page----

no matter what the username value it executes the else part
anyone knows why
[ November 10, 2005: Message edited by: pete duncan ]
 
Steve McCann
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pete

You should not compare Strings with ==. This compares them and returns true if they are the same String rather than having the same value. Try replacing that line and use the String's equals() method like this:


Cheers
Steve
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try with

if(s1.equals(s2)) {
--
-
-
}

ans username as leo
 
Leonardo Pjetri
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Steve
I should have known that doh
 
Leonardo Pjetri
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more thing guys
How would I modify the login page so that based on the input it post the data to different pages?
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by pete duncan:
One more thing guys
How would I modify the login page so that based on the input it post the data to different pages?


Its better to raise a new thread. A topic name should reflect the question inside the topic. I hope, you would get more results by doing so.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!