• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

if else

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Steve
I should have known that doh
 
Leonardo Pjetri
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic