Forums Register Login

if else

+Pie Number of slices to send: Send
<%@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 ]
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
try with

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

ans username as leo
+Pie Number of slices to send: Send
Thanks Steve
I should have known that doh
+Pie Number of slices to send: Send
One more thing guys
How would I modify the login page so that based on the input it post the data to different pages?
+Pie Number of slices to send: Send
 

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.
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2540 times.
Similar Threads
Killing session when closing the browser
sending data to jsp
Very funny behavior of sessions...
How to send Parameters from JSP to a Servlet?
Problem with syntax?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 00:07:29.