JSP code  
Author Message
bernardpace





PostPosted: 2004-12-20 23:52:00 Top

java-programmer, JSP code Hi,
I have the following code

<html>
<head>
<title>
Authentication
</title>
</head>

<body>
<%!
private String username = null;
private String password = null;
private boolean completeLoginInformation=true;
%>

<%
username = request.getParameter("username");
password = request.getParameter("password");
%>

<H2><p>Checking authentication...</p></H2>
<%
if (username == null)
{ completeLoginInformation = false;
%><p><H3>Username has been left empty...</H3></p>
<% } %>

<%
if (password == null)
{ completeLoginInformation = false;
%><p><H3>Password has been left empty...</H3></p>
<% } %>

<% if (completeLoginInformation == false) { %>
<p><a href="http://localhost:8080/jsp-examples/cal/Front.jsp">Return
back to Front Page</a></p>
<p><a href="http://localhost:8080/jsp-examples/cal/AdminLog.jsp">Return
back to Administration Authentication</a></p>
<% } else { %>
<p>Need to search in database</p>
<p>All data has been entered</p>
<% } %>

</body>
</html>

Now when username and password arguments are given as empty, the flag
is supposed to be set free and in the web browser shows me the 2 links
given. Instead, the else part is being given.

Can someone help me out

Thanks in Advance
 
Peter





PostPosted: 2004-12-21 6:39:00 Top

java-programmer >> JSP code "Xarky" <email***@***.com> skrev i en meddelelse
news:email***@***.com...

<snip>

> <%
> username = request.getParameter("username");
> password = request.getParameter("password");
> %>
>
> <H2><p>Checking authentication...</p></H2>
> <%
> if (username == null)
> { completeLoginInformation = false;
> %><p><H3>Username has been left empty...</H3></p>
> <% } %>

<snip>

Maybe username is an empty string (instead of being null). Try a test like:
if ( username == null || username.length == 0 )

Peter


 
fauna5





PostPosted: 2004-12-21 21:21:00 Top

java-programmer >> JSP code Maybe username is the string "null" passed through by a previous
servlet. You'll know if you get a string length of 4

 
 
bernardpace





PostPosted: 2004-12-22 0:05:00 Top

java-programmer >> JSP code Thanks problem solved