This is my user validation page. I want to pass the user Name in the ArrayList after checking the user password and id. After that I want to display the name in the main page but, I am getting null value in my main page. How can add the user name in the ArrayList?
// DwB: I love sql injection attacks - this is bad.
rs=st.executeQuery("select * from registration where U_ID='"+
U_ID+"' and Pass='"+Pass+"' ");
while(rs.next()){
na1=rs.getString("U_ID");
pw=rs.getString("Pass");
Name=rs.getString("U_N");}
if((U_ID.equals(na1))&&(Pass.equals(pw))){
HttpSession session=request.getSession();
//List<String> user= new ArrayList<>();
//String id=(String)session.getAttribute("ID");
//session.setAttribute("loggedIn",Name);
String username = request.getParameter("Name");
List<String> users = (List<String>)session.getAttribute("users");
if(null == users) {
users = new ArrayList<String>();
}
users.add(username);
session.setAttribute("users", users);
//response.sendRedirect("Welcome.jsp");
request.setAttribute("U_ID",na1);
request.getRequestDispatcher("/Welcome.jsp").forward(request, response);
PreparedStatement. It pains me (and many others) to seeStringconcatenation in SQL queries.