0

Hey lads,

Just have a small query here thats really bugging me. When details are entered by user and checked in database, the program should display one of two messages as seen below. When the details are entered correctly the welcome message displays correctly. However, when incorrect details are entered, the second message does not display. In fact, there is a blank screen. Anyone have any ideas?

<%ResultSet rs = stmt.executeQuery ("SELECT * from table where name='" + request.getParameter ("name")+"'");%>

    <%while (rs.next()){
    String st_id = rs.getString ("name");

    if(st_id.equals(request.getParameter ("name"))){

        out.print("Welcome " + request.getParameter ("name"));
     }else {
        out.print("Please try again.");
    }
    }
%>
4
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by Bobon
0

Yes, this is a basic JSP/JDBC problem. It is exactly what you should not be doing. Learn what beans are and use them. Or, at least, the SQL JSTL tags.

0

Cheers for the condescending reply. Can anyone else with my problem?

0

It is not condescending, at all. Scriplets in your JSP is a mixing of the model and the view (and, quite probably, the control) and a maintenance nightmare. If you are going to do something, regardless of on what scale, you can at least attempt to do it right.

0

OK i have a limited knowledge of javabeans. I have created a javabean and created an instance of it in the code below.

<%DBConnection.getConnection();
Statement stmt = DBConnection.getConnection().createStatement();%>


<%
      String name = request.getParameter ("name");
      getBean john = new getBean(username);
%>

<%ResultSet rs = stmt.executeQuery ("SELECT * from table where name='" + john.getName()+"'");%>

    <%while (rs.next()){
    String st_id = rs.getString ("name");

    if(john.getName().equals(st_id))

        out.print("Welcome " + john.getName());         
    
     else
         out.print("Unknown user. Please try again.");
    }
%>

Is this what you mean by using beans. If so, my code still won't print out the 'unknown user' message when it should. Any ideas why? P.s I just took the relevant code.

Edited by Bobon: n/a

0

OK i have a limited knowledge of javabeans. I have created a javabean and created an instance of it in the code below.

Why don't you try to follow tutorial from top of JSP section about MVC2?

0

Peter, thanks a million. Just going through the jsp example now.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.