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.
Related
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*.
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.
Here is the case.
User should be able to open MS Word document which is located somewhere in the network (ie. \remote\machine\documents\document_to_edit.docx) with MS Word 2007 by clicking link in the browser. Browser is IE7+.
Edit the document, close it and save it (no "Save as..." just "Save") in the same place in the network (\remote\machine\documents\document_to_edit.docx)
Is that at all possible? If so how should I do that?
Don't think this is relative, but I'm using JAVA + Wicket for my web application.
EDIT:
Any suggestions are welcome.
Main thing is - open file as it was on your computer and save it after edit.
(Read update below)
Short answer: not possible.
Long answer: When you open anything from a browser, even some local file, it will open the given file from the browser cache (or some temporary download directory) but not the original file linked. Therefore, after you save the changes the copied file will be updated.
Added:
Ok, after I thought about it for a while, there could be some ways to do it in intranet application. Here's how: Java applet: run native code from browser?
So, basically, you will serve the applet which will communicate with your javascript (I guess this way would be easiest to implement) (info on how to do it) and send a network path to the applet. Applet will start winword.exe passing it the required parameters.
Or, there's another option with ActiveX: http://codereflex.net/how-to-run-exe-on-webpage/ . The downside is - it works only with IE, but that seems what you need anyway.
IE can open \\server\share\file.docx type links and it opens the original file, not a downloaded version. You may need to add the domain of your http server to trusted sites in the security settings of IE first though. Have tested this and it does work
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.
Is there any way to download an applet embedded in a webpage of a site www.abc.com1, to one's system?
Or is it possible to extract its code for offline use?
E.G. http://www.falstad.com/dotproduct/
For the link provided, I see the link "Zip archive of this applet.". It contains the applet jar, html page and the java source file.
You can try to inspect the page source to see the archive file it is using. In this case, it appears as if it is using http://www.falstad.com/dotproduct/dotproduct.jar. You can use this in a project, but the source will not be attached.
The applet at http://www.falstad.com/dotproduct/ can certainly be used off-line. I tested it just to make sure.
You would need to download the dotproduct.jar (referenced in the page - are you familiar with "View Source"?) to the local file-system then create an HTML (or use a copy of Paul Falstad's own HTML) to launch it.
You might try "Save page as" for the 2nd part, but I am not confident that that would also download the Jar of the applet itself.
Of course, it would be courteous to let Paul know what you are doing. You might find he will be prepared to send you a Zip of the HTML/applet.