Forums Register Login

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

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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"
+Pie Number of slices to send: Send
Thank you, this did the trick!
See where your hand is? Not there. It's next to this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1233 times.
Similar Threads
Passed IBM 829
url link in a portlet
JSF and Portal
Bad Magic Number Loading Portlet/Applet
"Bad Magic Number" Loading Applet/Portlet
Portal Deployed;but cant see it.
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 07:20:27.