Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Error displaying parameter  RSS feed

 
john can
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
john can
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
guys..

n e solution with tht ? thanks
 
Ravinder S Edhan
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
john can
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks guy.. it's done
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!