• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dumbest question in the world... URLs, EMBED, and portlets

 
Tony Ennis
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a portlet that's failing. An EMBED is using a relative URL but this can't be counted on the be the same in production.

(My portlet generates a PDF and the jsp displays this with EMBED)

Does EMBED work with "file://" type URLs? So far as I can tell, it does not.

Otherwise I don't know how to refer to the PDF. I don't know what the default location is going to be (Jetspeed is using 'jetspeed/webapps/jetspeed/deploy' or similar) so I can't use a relative URL. And the "file://" URL doesn't seem to work.

Any hints? I'm totally brain locked.
 
Costi Ciudatu
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know about embed-ding a "file://" but file:// instructs the browser to search on the local file system, so you can only access that on localhost.
On the other hand, you CAN use relative URLs without caring where the application server will deploy your app. Just put the pdf in the root of your war (for instance) and access it as <c:url value="/file.pdf"/> ('c:url' will will add the context name). You need to import the JSTL core taglib for this to work.
 
Costi Ciudatu
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, if you need to know where you are (the file system path) at runtime, you can use the getRealPath("/file.pdf") in ServletContext to get its actual location on the file system.
 
Tony Ennis
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're probably getting close to my problem.

As far as I can tell, when I use the portlet, the default location for files is one place - but in my java, the default location is someplace else.

For example:

I create a temp directory and then create a tmp file for my PDF within it:



That temporary directory is being created under "C:\apache\Jetspeed-2.2.0\webapps\MyAppName\" A typical pdf would be at:
"C:\apache\Jetspeed-2.2.0\webapps\MyAppName\temp\snap12345.pdf"

However, to access that PDF, I'd use the following relative URL:

src="../../../MyAppName/temp/snap12345.pdf"

So it seems the browser thinks the root is where the war is (guessing) and the application thinks it is where the war expanded to.
 
Costi Ciudatu
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getRealPath() takes a virtual path as parameter: that means the same path that you type in your browser.
It only refers to files and directories under your webapp root: C:\apache\Jetspeed-2.2.0\webapps\MyAppName, in this case. So that behavior is exactly as expected.

For accessing it, your src should read: src="<c:url value="/temp/snap.pdf"/>", which will output: src="/MyAppName/temp/snap.pdf"
 
Tony Ennis
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, this did the trick!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic