CarneiroPJ 3 de dez. de 2007
Oi Leo,
você tem que recuperar a imagem do servidor e jogá-la no browser do cliente.
JhonatasPJ 3 de dez. de 2007
Dae cara.. eu fiz algo parecido.... tu cria um servlet e na tag img src tu passar esse servlet com o id da tua imagem.. é mais ou menos isso:
public class ServLoadImage extends HttpServlet & #123;
public void service & #40;HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String arquivo ;
try & #123;
arquivo = request . getParameter & #40;"id");
File file = new File & #40;arquivo);
this . download & #40; file.getName(), read( file ), response );
& #125; catch( IOException e ) {
try & #123;
throw new IOException & #40;e.getMessage());
& #125; catch (IOException ex) {
ex . printStackTrace & #40;);
throw new ServletException & #40;e.getMessage() + " :: Erro ao carregar arquivo");
& #125;
& #125;
& #125;
// Passe para esse método um File com o arquivo desejado .
public void download & #40; File file, HttpServletResponse response )
throws IOException & #123;
this . download & #40; file.getName(), read( file ), response );
& #125;
// Lê o arquivo no servidor
public byte & #91;] read( File file ) throws IOException {
byte & #91;] content = null;
int fileLength = & #40;int) file.length();
FileInputStream fileInput = null ;
try & #123;
fileInput = new FileInputStream & #40;file);
BufferedInputStream bufferedInput = new BufferedInputStream & #40;
fileInput & #41;;
content = new byte & #91;fileLength];
bufferedInput . read & #40;content, 0, fileLength);
bufferedInput . close & #40;);
& #125; finally {
if & #40;fileInput != null) {
fileInput . close & #40;);
& #125;
& #125;
return content ;
& #125;
// Faz o download do arquivo
public void download & #40; String filename, byte[] content,
HttpServletResponse response & #41; throws IOException {
response . setContentType & #40; "image/jpeg" );
ServletOutputStream outStream = response . getOutputStream & #40;);
// envia o conteúdo do arquivo para o stream de resposta
try & #123;
outStream . write & #40; content );
outStream . flush & #40;);
& #125; finally {
outStream . close & #40;);
& #125;
& #125;
...
e no jsp tu faz isso:
<img src="ServLoadImage?id=<%=tipo.getArquivoPBancoImagem()%>" />
Acho que pode te ajudar..
Abraço e fica com Deus!!
esqueletoPJ 11 de dez. de 2007
kra da pra colocar o codigo completo da .jsp queria saber de onde vem esse tipo do codigo abaixo
<%=tipo.getArquivoPBancoImagem()
Esqueleto