• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Fetching information from database in jsp

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good day everyone Please i needs help.This code was used to fetch information from database.
whenever a correct id at BEANS.JSP is entered ,it will fetch every information from that row.
But the problem am having is that it will retrieve every information on that row but the Image cannot
be retrieve instead it will retrieve image link.Please how do i solve this problem using JSP only.

Thanks for help.

below is the code

-----------BEANS.JSP------------




-------------------BEANS.JSP--------------------------




 
Sheriff
Posts: 28401
100
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I'm not sure if I understand what you are trying to say. But that code up there looks like you're actually getting an image out of the database -- not a URL pointing to the image, but the actual image itself -- and then trying to send it to the client in a place where HTML requires you to put a URL pointing to the image.

Well, you can't do that. You are going to have to produce HTML which contains a URL which points to the image. Obviously the URL can't point to the database column, so it will have to point to a servlet which returns the image. It would have to have a parameter which identifies which image to return, and the servlet would have to set up the response so that the browser knew there was an image being sent, not HTML. Which is why it should be a servlet and not a JSP which returns the image.

Actually most of that code should be in a servlet, not in a JSP. But that's a separate topic. And your JDBC code should be using a PreparedStatement instead of the unreliable method of creating a query by concatenating strings, but that's another separate topic.
 
fredrick esedo
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your reply i appreciate your help
Okay i develope this servlet code it retrieves all the informations on every row when a correct ID corresponding to that row is entered at
BEAN.JSP. Let assume that i have 2 rows in my database with ID 1,2 etc when i enter ID 1 i will get every information in that row
it works,but if enter ID 2 at BEANS.Jsp, before it will fetch that data at row 2 corresponding to ID 2 i entered it will require me to manually go to RICE.JSP and change the ID values eg to 2 ie id=2 otherwise it will keep on fetching all data at row 1.
Please sir how do i circumvent this problem so that any id i entered it will retrieve that row automatically with requiring me to be edicting the id manually eg id=1,id=2 and so on.

thanks






----------------rice.jsp--------------------




-------------------BEANS.JSP----------------------
 
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you're completely missing how to serve an image to a web application. Have a look at the ServletsFaq - there is an article on creating an Image Servlet which should help you which you can see here: http://faq.javaranch.com/java/ImageServlet
 
fredrick esedo
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good day everyone, please when i run this code it keeps on telling me the error below whereas i have commons-upload.jar and common-io.jar file in my both directory TOMCAT/lib and FREA/WEB-INF/lib.
but if run servlet it will run and no such error will be displayed.Is there any other dependecy jar file i need to install so that this error below will stop occuring
thanks and have a wonderful day





 
Ranch Hand
Posts: 38
IntelliJ IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

fredrick esedo wrote:Is there any other dependecy jar file i need to install so that this error below will stop occuring




No.. This has nothing to do with dependencies. The error is generated from here:


So do a print as mentioned below and check weather you have produced the name correctly after all those String manipulations.


Regards,


 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

fredrick esedo wrote:



It seems you're not trying very hard to debug this problem. In looking at this error, it's telling you that you have a FileNotFoundException when trying to open a FileOutputStream from within a JSP page. Doesn't that give you any clue at all about where the problem might be? Does your JSP page attempt to open a FileOutputStream anywhere? If so, what is the file name you're passing to it? Is the file name valid?

You should try harder to ShowSomeEffort.

By the way, it seemed originally you were trying to extract an image from the database and display it in the browser, but now you seem to be attempting to upload a file to the server. What's the deal? Has the problem changed? Perhaps you should create a new topic for the new problem.

If you're trying to upload files to the server, have a look at the FileUpload library from Apache Commons: http://commons.apache.org/fileupload/using.html

Finally, you really, really shouldn't be doing any Java programming in the JSP page itself. The JSP page should be used to gather user input and display results. The application logic should be in (or behind) a Servlet. Have your JSP page just gather the user input and POST to a Servlet, where you can do all your application logic. If you continue to try to execute your application logic in the JSP page, you're going to have a lot of difficulty.


 
fredrick esedo
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks very much, the problem has being resolved
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps you could share the solution with everyone?
 
reply
    Bookmark Topic Watch Topic
  • New Topic