aspose file tools*
The moose likes Servlets and the fly likes Problem show file png after create it Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem show file png after create it " Watch "Problem show file png after create it " New topic
Author

Problem show file png after create it

Principe Folle
Greenhorn

Joined: Apr 19, 2013
Posts: 5
File jsp


Servlet


the file is created successfully but I can not show it in jsp page even if the file path is correct and the file is present in that folder
How or what do i do??
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61661
    
  67

According to your image tag, the browser will be looking for the image file in the app context (the folder that serves as the root of the web app and contains WEB-INF). Is that really where it is being written? What happens when you type the URL to the image into the browser's address bar? Does it appear?

It's really bad form to be hard coding the file path in the code. Are you sure that it's correct? What happens when the web app gets moved elsewhere?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Principe Folle
Greenhorn

Joined: Apr 19, 2013
Posts: 5
Bear Bibeault wrote:According to your image tag, the browser will be looking for the image file in the app context (the folder that serves as the root of the web app and contains WEB-INF). Is that really where it is being written? What happens when you type the URL to the image into the browser's address bar? Does it appear?

It's really bad form to be hard coding the file path in the code. Are you sure that it's correct? What happens when the web app gets moved elsewhere?


Yes the file is show when write the same path into the browser's address bar.

If I put the path to an image created earlier and insert the code you see but do not see one currently created
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18911
    
    8

So your servlet is generating an image, and you want to display that image? Then the way to do that is to copy the image to the servlet's output stream. Don't forward to a JSP because you're just going to be using this servlet to generate and return the image, nothing else.

If your original design was to have the servlet generate both the HTML and the image, you'll need to change that. Have one servlet forward to a JSP which generates the HTML, including an <img> tag which requests the second servlet, the one which just returns the image. Make sure the image-generating servlet sets the response headers to say what kind of image it's returning.
Principe Folle
Greenhorn

Joined: Apr 19, 2013
Posts: 5
Paul Clapham wrote:So your servlet is generating an image, and you want to display that image? Then the way to do that is to copy the image to the servlet's output stream. Don't forward to a JSP because you're just going to be using this servlet to generate and return the image, nothing else.

If your original design was to have the servlet generate both the HTML and the image, you'll need to change that. Have one servlet forward to a JSP which generates the HTML, including an <img> tag which requests the second servlet, the one which just returns the image. Make sure the image-generating servlet sets the response headers to say what kind of image it's returning.


Mmm ... so basically what should I do?
Create a servlet to generate the image
Create a servlet that call in the path of the image?
But what I do not understand is why this does not work?
Yet the code of the image src is correct
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18911
    
    8

I don't understand what you're trying to do with that file path. If you're trying to send it to the client machine, that isn't going to do anything because the client machine doesn't have access to file paths on the server. And interpreting it as a path on the client machine won't do anything either because the file isn't on the client machine.
Principe Folle
Greenhorn

Joined: Apr 19, 2013
Posts: 5
Paul Clapham wrote:I don't understand what you're trying to do with that file path. If you're trying to send it to the client machine, that isn't going to do anything because the client machine doesn't have access to file paths on the server. And interpreting it as a path on the client machine won't do anything either because the file isn't on the client machine.


So the things to do is this:
Create a file qrcode / / and the class makes it
This file created by the client to be displayed on the page index.jsp

How should I do to see this image on the page?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61661
    
  67

Actually, all he's passing to the JSP is the file name, not the entire path.

In any case, if this is a temporary file that's generated each time the page is shown (which I assume is true from the code), then saving it to a file is wasteful and unnecessary.

Rather, create another servlet (not the one that forwards to the JSP) and have the image tag in the JSP use the URL of that servlet as its src. The new servlet will generate the image and stream it as its response rather than writing it to disk.

The sequence would be as follows:

1) Original servlet forwards to JSP. It does not try to generate the image,
2) JSP contain image tag that references the new servlet.
3) New servlet uses BarCode class to create image data, sets response headers appropriately, and sends the image data as the response.
4 ) Profit!
Principe Folle
Greenhorn

Joined: Apr 19, 2013
Posts: 5
Bear Bibeault wrote:Actually, all he's passing to the JSP is the file name, not the entire path.

In any case, if this is a temporary file that's generated each time the page is shown (which I assume is true from the code), then saving it to a file is wasteful and unnecessary.

Rather, create another servlet (not the one that forwards to the JSP) and have the image tag in the JSP use the URL of that servlet as its src. The new servlet will generate the image and stream it as its response rather than writing it to disk.

The sequence would be as follows:

1) Original servlet forwards to JSP. It does not try to generate the image,
2) JSP contain image tag that references the new servlet.
3) New servlet uses BarCode class to create image data, sets response headers appropriately, and sends the image data as the response.
4 ) Profit!


This code I posted is a test.
just put the file name because the path is just the name because it is located in the root folder ..
Each time the file is to be displayed when the user selects the options.
The file must also be downloaded later.

Something I had already done and works but call the servlet within the path of the tag img src="nome servet but I would simply display a file created dynamically in my application.
The same image is displayed on the next restart of the application but when I create is not seen.
Firefox in media info shows me a strange thing. But the same file when you restart the application appears



[Thumbnail for Immagine.png]

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem show file png after create it