This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Converting JSP to servlet  RSS feed

 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
following is the code


how can we write following line in servlet
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you want to to do that?

Granted, putting JDBC code into a JSP is a bad practice, but so it emitting HTML from a servlet.

if you are going to refactor this code, you should move the JDBC code into the Model layer, and use the servlet to fetch the data from the model as a Java collection, not a result set. This collection will be sent to the JSP page for creating the view.

For more information of properly structuring web apps please read this article.
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Megha Singhal wrote:following is the code


how can we write following line in servlet

i convert it like following, am i wrong somewhere.
 
bhavesh gawade
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

As long as above servlet code is working well there is no issue. But it might suffer from performance related issue if number of records are more in ResultSet. Use StringBuffer object in loop to create entire output string and then pass the same to out.println() function.
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bhavesh gawade wrote:hi,

As long as above servlet code is working well there is no issue. But it might suffer from performance related issue if number of records are more in ResultSet. Use StringBuffer object in loop to create entire output string and then pass the same to out.println() function.


Thanks for your help, my problem has solved.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!