wood burning stoves 2.0*
The moose likes Servlets and the fly likes Accessing a jpeg or gif in an unpacked war file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Accessing a jpeg or gif in an unpacked war file" Watch "Accessing a jpeg or gif in an unpacked war file" New topic
Author

Accessing a jpeg or gif in an unpacked war file

adrian mills
Ranch Hand

Joined: Dec 09, 2004
Posts: 63
Hi All,

I have a unpacked EAR file as well as a unpacked WAR file which I deploy in my application server.

The ear structure is as follows

MyProject.ear
|
|--MyProject-WebApp
|____Adv
|____MyAdv
| |_images
| |_logos
| |_MyPortrait.jpeg
|
|____WEB-INF
|_Classes

I want to access the MyPortrait.jpeg in my servlet which will be there in the packed war.
How should I give the relative path to MyPortrait.jpeg in my servlet file.

If anyone has done it please help?
Thanking you in advance.
Oh If you want to know the application server I am using it is Orion1.5 application server.
Thanks a lot
With Regards
Adrian
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Exactly the same way you would if it wasn't packed.
Relative the url of the servlet that is calling it.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
adrian mills
Ranch Hand

Joined: Dec 09, 2004
Posts: 63
No the path is not resolved.
I am giving ../MyAdv/images/logos/MyPortrait.jpeg.

It gives a file not found exception.
The path it takes is
D:/Orion1.5/MyAdv/images/logos/MyPortrait.jpeg.

It is not resolved properly.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

What is the URL you are using to hit your servlet?
adrian mills
Ranch Hand

Joined: Dec 09, 2004
Posts: 63
Hi I am clicking a button called Export to pdf which submits a form with the following Action


/Adv/MyController?Action=ExportToPDF to my Servlet which is MyController.java.

Adv is the folder in which all the JSP pages are residing.

This page on which the button is displayed is a report.Which I want to export to PDF.
While exporting I am giving it the relative path to include the Image in the pdf.

The path is /MyAdv/images/logos/MyPortrait.jpeg
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by adrian mills:
Hi I am clicking a button called Export to pdf which submits a form with the following Action


/Adv/MyController?Action=ExportToPDF to my Servlet which is MyController.java.

Adv is the folder in which all the JSP pages are residing.

This page on which the button is displayed is a report.Which I want to export to PDF.
While exporting I am giving it the relative path to include the Image in the pdf.

The path is /MyAdv/images/logos/MyPortrait.jpeg


First, it's a bad idea to include the contextPath ("/Adv") in your code. This makes it very difficult to change the app's name later.

If you're calling your servlet with "/Adv/MyController" Then any links or image src attributes need to be relative to that URL.
IOW: relative to "http://www.domainname.com/Adv/"
Or... one directory up from the root of the app.
src="../images/logos/MyPortrait.jpeg"
adrian mills
Ranch Hand

Joined: Dec 09, 2004
Posts: 63
First, it's a bad idea to include the contextPath ("/Adv") in your code. This makes it very difficult to change the app's name later.

If you're calling your servlet with "/Adv/MyController" Then any links or image src attributes need to be relative to that URL.
IOW: relative to "http://www.domainname.com/Adv/"
Or... one directory up from the root of the app.
src="../images/logos/MyPortrait.jpeg"


Ya when i keep the src as "../images/logos/MyPortrait.jpeg"

The error is file not found exception and the path it displays is
D:\Orion1.5\..\images\logos\MyPortrait.jpeg.

Do u think there is something missing in the web.xml file.

When I give a absolute path the Image is displayed properly..:?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

What is the url-pattern for the servlet you are hitting?
(from the servlet-mapping entry in your web.xml file)
adrian mills
Ranch Hand

Joined: Dec 09, 2004
Posts: 63
Hi Ben here is the servlet mapping in web.xml
<servlet>
<servlet-name>MyController</servlet-name>
<display-name>MyController</display-name>
<servlet-class>com.test.MyController</servlet-class>
</servlet>


<servlet-mapping>
<servlet-name>MyController</servlet-name>
<url-pattern>/Adv/MyController</url-pattern>
</servlet-mapping>

The strange thing is when I give a absolute path everything gets resolved fine
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing a jpeg or gif in an unpacked war file
 
Similar Threads
.ear file and .war files
JEE5 bean and war deployment
How can I deploy unpacked war on WebLogic?
debug j2ee web application using eclipse
Do we have Application specific class-path?