• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Accessing a jpeg or gif in an unpacked war file

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exactly the same way you would if it wasn't packed.
Relative the url of the servlet that is calling it.
 
adrian mills
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the URL you are using to hit your servlet?
 
adrian mills
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic