File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Display values form database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Display values form database" Watch "Display values form database" New topic
Author

Display values form database

Madhuri Abhi
Greenhorn

Joined: Jun 29, 2011
Posts: 11
Hi

I have a table with the fields id, name and the content(of the file saved as blob in the database). I want to retrieve them in jsp page and show just id and name in a tabular form.(which i am able to do).

Afetr displaying the values, the I should be able to see the full content when I clicks on the name that has been displayed in the table.

I am attaching the code below.



I want the file to be opened when i click on the below name.
a href="/imageAndDoc/download1.jsp"><%out.println(rs.getString("name"));%></a


Please help.

Thanks,
Madhuri
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1


JSP is intended for dynamic display purposes and including business logic/application logic is not in conformance with MVC specifications. You ought to move the database manipulation code to a Servlet/Action class.

Steps
1. From the Action/Servlet instance obtain the Connection, fetch the relevant data and pass it in a suitable Collection class to the JSP.
2. In the JSP iterate through the Collection obtained from above and display the data as required.

Cheers,
Raj.
Madhuri Abhi
Greenhorn

Joined: Jun 29, 2011
Posts: 11
Hi Raj,

Thanks for the reply. i haven't followed MVC since i just want to check it. Once i get the solution, I would follow MVC.

What you told is for just displaying the values in jsp from database. What i want to do is something different. Please go thrugh my previous post once again.

I have id, name and conetent fields. I can display id and name (in table) in jsp by having a servlet(action) and DAO(java class). When i click on any of the name displayed, i want its content(i.e the file) to be shown.

How can i do that? Any idea?

Thanks,
Madhuri
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1

Madhuri,

Show the Name as a link for each row in the table. On click of the link call the 'Action' to display the detail in a new page alternatively you could also use Javascript to show a new window popup. Pass the parameters in the Query String. You should be able to display them in the popup.

Cheers,
Raj.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Display values form database
 
Similar Threads
problems validation.xml in struts 2
Login JSP if condition and redirecting issue
Ordered List tag inside jsp
Get a href id from jsp to servlet
wrong jar reference