NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
kawalya
Joined: 07 Sep 2009 Posts: 12
|
Posted: Tue Apr 13, 2010 4:43 pm Post subject: Problem sending images to browser |
|
|
Hi folks,
I am having a little problem in Netbeans 6.5.
I am in the JSF managed bean;
I call
| Code: | | System.getProperties(“user.dir”) |
to get the current working directory and get
| Code: | | /home/dk/glassfish-v2.1/domains/domain1/config |
So I upload an image file and create a copy in the file system relative to the above ie
| Code: | | web/Images/myImage.jpg |
Checking in the application server, the image actually exists on the above path.
So I store another copy of the image bytes, the above path, and other image parameters in the database.
I direct to the above url to get the image.
Running the application, the image is not displayed, but an anchor thumbnail showing there is supposed to be an image on the page.
I click on the displayed thumbnail and choose properties to get the image location and get
| Code: | | location = http://localhost:8080/MyImages/faces/+/home/dk/glassfish-v2.1/domains/domain1/config/web/Images/myImage.jpg |
I right click again and choose view image and get
| Code: | HTTP Status 404 -
type Status report
message
descriptionThe requested resource () is not available.
Sun GlassFish Enterprise Server v2.1
|
So how do I then direct the system to find the image?
Any help will be appreciated.
Thanks. |
|
| Back to top |
|
 |
kawalya
Joined: 07 Sep 2009 Posts: 12
|
Posted: Thu Apr 15, 2010 12:11 pm Post subject: |
|
|
This was solved.
The problem was creating files in the application server as opposed to the project folder. |
|
| Back to top |
|
 |
kawalya
Joined: 07 Sep 2009 Posts: 12
|
Posted: Thu Apr 15, 2010 12:11 pm Post subject: |
|
|
This was solved.
The problem was creating files in the application server as opposed to the project directory. |
|
| Back to top |
|
 |
kawalya
Joined: 07 Sep 2009 Posts: 12
|
Posted: Wed Apr 28, 2010 4:11 pm Post subject: |
|
|
I think a better aproach is even using a servlet ie
The database entity POJO is as below
| Code: |
public class DavisContent implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@Column(name = "content_id")
private String contentId;
@Basic(optional = false)
@Column(name = "content_type_id")
private String contentTypeId;
@Basic(optional = false)
@Lob
@Column(name = "content")
private byte[] content;
.
.
}
|
Then the image loader servlet
| Code: | private DavisContent davisContent = null;
@PersistenceUnit(unitName = "DavisBlobsPU")
private EntityManagerFactory emf = null;
public EntityManager getEntityManager() {
return emf.createEntityManager();
}
public DavisContent findDavisContent(String id) {
EntityManager em = getEntityManager();
try {
return em.find(DavisContent.class, id);
} finally {
em.close();
}
}
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//This is the parameter from the h:graphicImage tag
String file = request.getParameter("file"); davisContent = findDavisContent(file);
try {
if(davisContent.getContentTypeId().contains("image")){
response.getOutputStream().write(davisContent.getContent());
}
} finally {
//out.close();
}
}
|
The servlet configuration in web.xml
| Code: | <servlet>
<servlet-name>ImageServlet</servlet-name>
<servlet-class>dave.ImageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ImageServlet</servlet-name>
<url-pattern>/image/*</url-pattern>
</servlet-mapping>
|
Then finally one of the columns in the h:dataTable
| Code: |
<h:column>
<f:facet name="header">
<h:outputText value="Content"/>
</f:facet>
<h:graphicImage height="50" width="40" value="/image?file=#{item.contentId}">
</h:graphicImage>
</h:column>
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|