• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet problem, senRedirect not working.

 
sarojni agrwal
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am building project, in which I have a problem in jsp.



here, I created a form in jsp and fetch the value through servlet and also connect it with jdbc , all goes well means it fetched data correctly and goes into database correctly but my problem is


this line ,here result == 4 but it did not goes in my itemsdisplay.jsp, while when I created one item not 4 and used here result == 1 then it worked correctly why?
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm moving this post to Servlet forum. Please carefully select the forum (http://www.coderanch.com/how-to/java/CarefullyChooseOneForum) in future.
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't matter how many items you create. executeUpdate will return either 1 or 0. 1 on successful operation. so ==4 condition will never be satisfied.
 
Dave Tolls
Ranch Hand
Posts: 2091
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swastik Dey wrote:It doesn't matter how many items you create. executeUpdate will return either 1 or 0. 1 on successful operation. so ==4 condition will never be satisfied.


To be more specific, the return value tells you how many rows were affected by the SQL statement.
In this case, yes, it's either 1 or 0 as the SQL is simply attempting to insert a single line.
 
J. Kevin Robbins
Bartender
Pie
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Incidentally, having all that database access code in the servlet is really bad design. All that code should be moved to a DAO and you should be using connection pooling.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic