last day (14 days later) » 

10:43 AM
0
Q: Retrieve Image or any document from database using MVC pattern in java

sourav78611My program is working, but JSP page loading very slow that is my issue. I am passing empid and image name as a parameter from a jsp page to a Servlet which I am able to do perfectly and it is receiving in Servlet and calling data access class associated method, after that I am retrieving it and ...

 
Format your code first. no will help if other can not understand your code properly.
 
size is 250 kb so some issue is there...
@Yagnesh i have done some edit as you said..now is it helpful to you understand the problem
 
If this is for download file using JSP & servlet than this is not a good way. dont use scriplet it is old.
 
@Yagnesh i am calling one method which is in data access class their i am retrieving image and its type and adding into bean class object and trying to retrieve on jsp using scriptlet help me in this if you can..
 
You have a Servlet,in that you read your data from database, in output write this stream, same as you are doing in JSP.
 
10:43 AM
ok i got it i am doing same thing twice in jsp and servlet both place so tell me what should i do in jsp
 
You do not need to do anything in JSP. just read your data convert it into stream and write it into response of servlet request
 
11:02 AM
See this link javatpoint.com/…
 
ok
m checking it
sir that code is nothing which you have told me and that is related to retrieve from server and m retrieving from database it is not helpful
u there?
 
11:18 AM
that is for our reference..
you need same code as which you have written in JSP
 
see i have done all those thing
already and if anyone can do using reference then their is no need of communities where we ask question to each other then google is enough
because i have so many better references than that..
 
where did you face problem ?
 
see read my question you will come to know about the problem
can i give yo
one by one all files here
you can go through and i can tell the problem
3 files are there..
 
sure
 
k
package com.info;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@WebServlet(name = "Retrieve_Image", urlPatterns = {"/Retrieve_Image"})
public class Retrieve_Image extends HttpServlet {
static int p,i;
String a;

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
in this servlet i am getting emp id and image or document which he wants to see or want to download
in this all is correct
eb.RetrieveImg(emp1); ---here i am calling that method
and here is my method
public Employee RetrieveImg(Employee emp1){
Connection con = null;
Statement stmt = null;
PreparedStatement pstmt = null;
InputStream sImage;
ResultSet rs = null;
byte[] sImageBytes;
int z = emp1.getEmpId();
String q = emp1.getIname();
try {
int count =0;
con = ConnectionManager.getConnection();
stmt = con.createStatement();
String Query ="SELECT contentType, photo FROM upload_documets WHERE empId ='"+z+"' and Name ='"+q+"'";
rs = stmt.executeQuery(Query);
if(rs.next())
{
byte[] bytearray = new byte[1048576];
have u gone through it?
can i send last jsp file?
 
11:33 AM
no.. i will see and let you know
 
yea just check it and let me knwo
sir m waiting
 
11:51 AM
See my answer i have posted
 
i dont thnk you hv time to look on my code
ok i will c
sir all things i have put in my code
but what abut sImageBytes that variable u r using in servlet but
we have not retrieve and declared what to do wid dat
 
back to you in some time
 
yea i have declared a variable byte[] sImageBytes
will try and let u knw
its working same issue i dont knw why its showing and retrieving the last image or document again and again if i execute again and store other thing and try to see d result again last image or document will come only dont knw why..
 
12:14 PM
sImageBytes is the byte array got from database..
see updated answer
check if update is properly done in database or not
 
if update is properly done in database or not what does mean? are u asking images or document are gettin stored or not?
 
you say that after update i get the previous (last image) image so may be
 
i didnt mention update if i said it means after putting your suggestion and i am storing diff diff image and document into table, i am not updating table just storing things into it same result not helpful
 
12:38 PM
i thnk some problem i will check and tell u..
 

last day (14 days later) »