JavaServer Pages (JSP) and JSTL - retrieving and comparing password values -- not able to show e
I'm trying to fetch a user and password combo from the database and then compare with a request param.
I'm able to print out my error message to the console, but not to the browser at all.
It's in my JSP and here's my code:
<%
String username = request.getParameter("user_name_fld");
String userpwd = request.getParameter("user_pwd_fld");
String useremail ="";
String errmsg ="";
...
String prepJSQL ="SELECT USER_NAME, USER_PASS, USER_EMAIL FROM USERS_DEV WHERE " +
"USER_NAME = ? AND USER_PASS = ?";
PreparedStatement prepstmt = connection.prepareStatement(prepJSQL);
prepstmt.setString(1, username.trim()) ;
if ((!userpwd.equals(" ")) && (!userpwd.equals("")) && (userpwd !=null)){
prepstmt.setString(2, userpwd);
}
ResultSet rslts = prepstmt.executeQuery();
System.out.println("first test working?");
try{
if (!rslts.next()){
String errmsg ="That password is incorrect - try again.";
System.out.println("Bad password - try again.");
System.out.println(","+userpwd+""+errmsg);
System.out.println("Error!"+errmsg);
%>
<body><html>
<table><tr><td><P>stuff - bad error and password</P> </td></tr></table>
</html></body>
<%}
while (rslts.next()){
String usernam2 = rslts.getString(1);
System.out.println("UserNm: "+usernam2);
if ((username.equals(usernam2)) && (!userpwd.equals(rslts.getString(2)))){
System.out.println("Bad password - try again.");
System.out.println(","+userpwd+"");
}
if (rslts.getString(2).equals(userpwd)){
String userpwd2 = rslts.getString(2);
useremail = rslts.getString(3);
System.out.println("UserPwd: "+userpwd2);
System.out.println(userpwd2+","+userpwd);
}
else{
String userpwd2 ="";
useremail = rslts.getString(3);
System.out.println("Incorrect password - please try again!");
System.out.println("2nd case UserPwd: "+userpwd2);
}
%>
then in my HTML -
<body>
<%if (errmsg !=null || errmsg !="" || errmsg !=" "){ %>
<font face="arial" size="2" color="red"><%= errmsg%></font>
<%} %>
I also tried putting it near the end of the page after my while loop and that did not work either.
I'm open to suggestions should anyone have some!
Thanks!
[4412 byte] By [
bpropes20a] at [2007-11-26 23:08:31]

# 3
yeah....I should definitely do the latter, on that MVC part for certain.
No, I realize what System.out.print is versus out.print.
Maybe I didn't explain it well, but I thought I had!
I run system.out.print and see it in the console.
I ALSO run out.print (same stuff as System.out.print);
and it does NOT show up in the browser!
That's what I'm wondering about...why not?
and if you look at those other conditional statements, I wrote HTML in the page, actually between the String declarations.
Shouldn't that have worked?
I'll try variations of out.print again and see if there's any success, but it should have worked before one of the ways I was trying it.
BTW, I see you recommend JSTL, and I've heard it's great, though I've not used it really any.
Is Tomcat 4.1.3 sufficient enough to use it? JSTL I mean?
Message was edited by:
bpropes20
# 5
No, I realize what System.out.print is versus
out.print.
Maybe I didn't explain it well, but I thought I had!
I run system.out.print and see it in the console.
I ALSO run out.print (same stuff as
System.out.print);
and it does NOT show up in the browser!
I didn't see out.println in your original code so I assumed you may not know it.
That's what I'm wondering about...why not?
and if you look at those other conditional
statements, I wrote HTML in the page, actually
between the String declarations.
Shouldn't that have worked?
As mentioned in the above post, sometimes if the out.println is not properly nested in HTML tags they don't get displayed.
So click on "View Source" to see if you get the output in the HTML Source.
I'll try variations of out.print again and see if
there's any success, but it should have worked before
one of the ways I was trying it.
BTW, I see you recommend JSTL, and I've heard it's
great, though I've not used it really any.
Is Tomcat 4.1.3 sufficient enough to use it? JSTL I
mean?
I think only JSTL 1.0.x version will work with Tomcat 4.1.3
Because Tomcat 4.1.3 is built to Servlet 2.3 and JSP 1.2 specifications:
http://tomcat.apache.org/whichversion.html
I know for sure that JSTL 1.1.x version is supported on Tomcat 5.5.x and higher, but I'm not sure if Tomcat 4.1.3 supports JSTL 1.1.x , it should definitely support JSTL 1.0.x
Message was edited by:
bpropes20