Why do hyperlink in a document result in Page not found - java

I have written a Windows Java app (using NetBeans) that (a) uploads pdf files using FTP to my WordPress website, and (b) generates emails with embedded links to the various pdf files. E.g., the email recipients might get a email containing:
"...Here are PDF files containing the Placards. There's a separate PDF file for each Division for convenient printing on paper of different colors.:
To view Championship and Special Click on View"
where View is a hyperlink to the pdf previously uploaded to the website.
The app worked perfectly for several years and then I changed my hosting service to SiteGround. Now the hyperlinks bring up Page not found (404), even though FileZilla shows the uploaded files exactly where the hyperlinks indicates they should be.
SiteGround tech support told me to put the files below public_html, e.g. /concoursbuilder.us/public_html/JOCLA/MovieStars/Placards
This did not help.
I figure it must be a Java programming error because obviously FileZilla knows how to do it. Naturally, SiteGround is reluctant (unwilling?) to get into my Java programming issues. I'm at my wits end.
Any suggestions?

The problem is solved, thanks to answers to basically the same question, https://stackoverflow.com/questions/46417961
In a nutshell, it's a matter of FTP uploading to public_html at the site so that it is at the same level as the site. See the FileZilla structure shown below. You FTP upload is uploaded to public_html. And here's the punchline: The URL for public access is the same as used for FTP upload* but with out public_html*.

Related

Working with HTML and images on Google App Engine

I am a bit confused about how to deal with html and images on Google App Engine:
I am displaying a simple website on my naked domain (example.com), which is hosted on my Google App Engine directly in the war directory. This is working fine.
I have also built an API which I host on Google App Engine, and is available on example.com/api/v1/. Now, I am building a functionality in which a new user is being created and a registration confirmation mail is sent to the new user.
This email is a plain HTML page, which I load from war/WEB-INF/mail/register.html, because I do not seem to be able to get it from the war directory. In this HTML I just refer to an image with <img src="images/image.png" />, assuming GAE will search for it in /war/WEB-INF/mail/images/image.png, but this is not working. The image is never found.
I also looked at <static-files>, which needs to be placed in the app engine-web.xml, but I am a bit confused which home directory is used in this.
My question is: Can anyone explain how App Engine handles html and images in the war and WEB-INF directories?
Any help is greatly appreciated!
Note: My homepage is just working fine, so these images and css files work without any editing in the appengine-web.xml.
Note: I am using Java.
If this html is for an email, the image paths need to be the full url and not relative to the html file. For example, use:
<img src="http://example.com/images/image.png"/>
Also, images cannot be served if they are under the WEB-INF directory. Create a static directory to serve the images from.

Opening HTML files in SWT browser from .jar with hyperlinks working

I have a set of help files for my SWT application that I have open in-application using the Browser control. Navigation through the help files is done through hyperlinks of relative pathnames (i.e: <a href="aboutUs.htm">, so only one html file is actually opened by java code, helpHome.htm. I am opening this using String homeURL = this.getClass().getResource("/help/helpHome.htm").toString(); and browser.setURL(homeURL); This works beautifully when I'm just debugging it in Eclipse. Unfortunately, when I move the project into a .jar, the browser gives the standard "can't find this webpage" error. I've tried using the browser.setText(String); function as described in this link, which works for helpHome.htm, but when I click a hyperlink, it brings me to a blank page displaying the relative pathname. Is there a way to convince browser to open an html file from an executable jar using the setURL(String) method? If not, are there any suggested workarounds for me to achieve similar results?
Thanks in advance!!
You have to start an internal Server as explained here on any available port on your application start up and make your html files available as static resources to the server.
Then set the browser.setURL(homeURL). All the subsequent hyperlinks will now point to the server, which knows how to serve the requested resources.
The hyperlinks are resolved to File System Path (Ex. file://C:\workspace....) while you are running or debugging your application in eclipse and things were working fine then. But that is not the case when you run your app from a runnable jar.

Displaying images from outside of java application context.

This was a question about testing file upload functionality using a local java server on Windows 7 platform. Since the question evolved with Marko's input, I have edited it, so that those who run into the same challenge do not waste time on evolution details and reach conclusions sooner.
The challenge was to direct uploaded file to a folder outside of the WAR structure and successfully read it from there. For example: upload an image into c:/tmp/ and then redirect to a confirmation page that displays the image <img src="c:/tmp/test.jpg" />. The upload worked but image would not be displayed. And based on Marko's input, this makes sense because browser sitting at localhost will refuse to load anything from local disk structure using c:. Maybe these are security considerations similar to those with file input control where we cannot set a default path...
The following tag will work in a locally created .html file but when pasted into a jsp, it won't work. And the difference is that browser uses localhost to get to the jsp.
<img src="c:/tmp/test.jpg" />
Solutions
I think that Marko's answer pretty much defines what needs to be done. While I didn't go with that approach, it clearly is the better way to do it and I will accept that as the answer. Thanks, Marko!
For those who don't want to bother installing a Web server and are willing to live with a bit of a hack, here's what I have done. Again, I didn't want to upload files into my WAR structure because I would then need to remember about clearing that folder before deploying to the server. But that upload folder still needs to be accessible, so I simply created another dummy project and put that upload folder under its WebContent. This works for the purposes of my local testing. The only nuisance is that after uploading a file, I need to refresh the dummy project's WebContent in Eclipse.
config.properties
#for uploading files
fileUploadDirectory=C:/javawork/modelsite/tmp/WebContent
#for building html links
publicFileServicePrefix=http://localhost:8080/tmp
<img src="http://localhost:8080/tmp/test.jpg" /> // this works - tmp is the name of my dummy project.
If you are citing literally the HTML that goes to the browser (the one that you access via "vieew source") then this has nothing to do with Java. The browser is the one who interprets these links. If they fail to load, the problem is in the browser/file system.
UPDATE
According to the results of your additional diagnostics, I conclude that the browser (sensibly!) refuses to load anything from your local disk if it is referenced from an HTML file coming from an internet URL, even when that URL is localhost.
UPDATE 2
(Deleted, irrelevant)
UPDATE 3
However you handle the files uploaded to the server, it's definitely not going to look like your solution -- the file is on the server's local filesystem, not client's. This sort of thing can be handled at the Apache HTTP server level -- reserve an URL section for static content and configure Apache with a base directory from which to serve the static content. Even if you run the server locally, on the same machine where you test it, you still need to go through the network interface.

How to upload files with java applet?

I know similar questions have been asked but i have searched for hours and as of yet have not come up with a workable solution.
I have a Java applet which will be a "paint" like application. So, I need the user to be able to upload images from their file system. I first tried using a JFileChooser which works great in the eclipse environment. However, when put online i get a "java.security.AccessControlException: access denied" exception.
I was thinking that perhaps within the applet i could call a script (located on my server) which would prompt the user to select a file - but i have no idea how to do this. I am using zymic web hosting, so the only supported scripting language is PHP.
I also tried signing the applet. Since i don't want to spend money on certificates, i self signed the applet. When i tried running it, I got an error stating "The Publisher Cannot Be Verified By A Trusted Source".
Any help would be greatly appreciated. - Thanks:)
A trusted applet can most certainly load files from the local file-system. The "Publisher Cannot Be Verified By A Trusted Source" message that is produced by self-signed applets is onerous & scary (for good reason), but if the user OKs it, it works just fine.
Here is a small demo. of exactly that.
Since the 'Next Generation' Plug-In, even sand-boxed applets can access the local file system. See the last 2 links on the Applet tag info page for further details.
Here is an applet that uses the Next Generation file abilities.
Unsigned applets can not access the file system for security reasons.
There is a tutorial about uploading files using PHP here
Maybe you can work that into your page in order to allow the file to be uploaded and then load it from your web server with the applet.
Do keep in mind the warning at the end of that example under the section "php - file upload: safe practices"

Can't open generated .mht file from Tomcat webserver

I'm generating a custom Word documents in my web application using the .mhtml format. Previously this was working fine. I assemble the document and write it to a directory then give a link to the file (with a .doc extension). Recently my template has changed to include embedded images. Now when I attempt to save and open a file from the web app, Word refuses to open it. It just shows a message "Cannot open file .." with the path. When you view the help it says something about lack of memory which is bogus.
When I open the exact same file from my localhost server it works fine. The two files (local and production) are identical. I've tried adding the site as a Trusted Site - no luck.
Any ideas?
Jeff
Sounds like the webserver does not annotate with a correct mimetype.
Is the downloaded file identical with the one present in the webserver? Do a byte-wise comparison.
Also try other browsers to see. IE has some quirks.
Solved issue by switching to plain HTML format with images as external links.

Categories

Resources