I am developing a web application in JSP/Servlet, in which I am taking values from checkboxes and put that on session. After that I am adding this checkbox values one by one in database with some more attributes.
The problem is after taking values from checkboxes, the length of string is incresed, as you can see in stacktrace. For Example if String value is abc its showing its length as 5.
Please help me out if I am doing something wrong here.
case 1:
String[] checkbox = request.getParameterValues("c1");
if (checkbox != null)
{
session.setAttribute("title", checkbox);
}
break;
case 2:
String[] titles = (String[]) session.getAttribute("title");
for (String title : titles)
{
System.out.println(title + title.length());
}
int i = 0;
String Name = session.getAttribute("Name").toString();
String[] days = request.getParameterValues("t1");
if (titles != null && days != null)
{
for (String title : titles)
{
System.out.print(title);
System.out.print(title.length());
int day = Integer.parseInt(days[i]);
i++;
String query = "insert into rents values('" + day + "','" + Name + "','" + title + "')";
System.out.print(query);
cr.stmt.executeUpdate(query);
}
}
cr.stmt.close();
cr.con.close();
break;
This is what the error is, you can see that while printing query it is showing \n after the title.
Value abc is present in database also.
Aucun commentaire:
Enregistrer un commentaire