File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Converting JSP to servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Converting JSP to servlet" Watch "Converting JSP to servlet" New topic
Author

Converting JSP to servlet

Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 182

following is the code


how can we write following line in servlet
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 182

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

Joined: Aug 08, 2011
Posts: 4
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

Joined: Feb 28, 2012
Posts: 182

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Converting JSP to servlet
 
Similar Threads
How to get Names of selected checkboxes?
Showing resultSet
form handling in jsp
selecting multiple rows to update value
always get the value "20" no matter which checkbox I clicked