Forums Register Login

Error displaying parameter

+Pie Number of slices to send: Send
guys ;

<%! String status1; %>
<% String username = request.getParameter("text1");
String password = request.getParameter("text2");
if (username == "abc")
{status1 = "Login Not Authenticated";}
else
if (username != "abc")
{ status1 = "Authenticated"; }

%>
</br>
Username Entered : <%= username %></br> ..(a)
Password Entered : <%= password %> ..(b)
</br>
Status : <%= ali %>
</br>Result1 : <%= status1 %> ..(c)

-------------------------------------------------------------
p/s : text1, and text2 comes from a defined text box.

-------------------------------------------------------------
i have created a login page with 2 text boxes, as defined above.
in line (a) and (b) it prints out the text enteres. but it fails
to show output on (c). eg, if i keyed "abc" it dosnt show "Aut... ". means a failure in the "if" loop. please help. thanks.
-john
[ January 23, 2005: Message edited by: Bear Bibeault ]
+Pie Number of slices to send: Send
Two major problems with your code:

1) You are using == to compare string values. == checks for identity, not equality.

2) By declaring status1 as an instance variable you have introduced thread-safety issues into your JSP that can cause nothing but problems.
+Pie Number of slices to send: Send
guys..

n e solution with tht ? thanks
+Pie Number of slices to send: Send
Hi

Use 'equals' method to compare the strings.

Check this code
******************************
<%! String status1; %>
<html>
<body>
<FORM METHOD=POST ACTION="login.jsp">
Username: <INPUT TYPE="text" NAME="text1"><BR>
Password: <INPUT TYPE="password" NAME="text2"> <BR>
<INPUT TYPE="submit" NAME="submit" VALUE="Submit">
<%
String username = request.getParameter("text1");
String password = request.getParameter("text2");
%><BR><%
out.print("username: " + username);
if (username.equals("abc"))
{
status1 = "Login Not Authenticated";
}
else
{
status1 = "Authenticated";
}
%>
</br>
Username Entered : <%= username %></br>
Password Entered : <%= password %>
</br>
</br>Result1 : <%= status1 %>
</FORM>
</body>
</html>
+Pie Number of slices to send: Send
thanks guy.. it's done
The first person to drink cow's milk. That started off as a dare from 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 864 times.
Similar Threads
JSP Tag Error
Problem in Login page
frecuent users with cookies
Giving new line from the string
Passing values through html
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 01:55:21.