J2EE: file access from web server. - java

I am trying to develop a J2EE web application which reads files from the local machine. The user will be able to enter a path where the file exists and when a button is clicked, the file is read and a database should be uploaded. This feature works fine when I tested it locally, but when I moved the code to the web server, it is not able to find the file. This is because the application is trying to find the file at the server and not the local machine. Could some one please let me know if there is any way I could read the file from the local machine?
I ve been using struts/tomcat for developing this application
Thanks

An option: Check out this Rose India article
Another option: do a google search for "file upload jsp"

try
<input type="file"/>
It is impossible to read a file on a remote computer without sending it to the server... obviously!

Local file access is usually permitted if you run the browser App from the local file system, and not thru an Web server.

Related

reading logs and displaying them on a web browser using Java

I have logs in folder /home/a/b (located in a remote server)
I want to display logs in my web browser using Java. To get data in the folder /home/a/b and to display them on my web page, what are some methods(API) I can use?
The simplest approach I can imagine is using a SSH API like JSch,
but I don't know how performatic this is.
Anyway, here goes a good example:
https://stackoverflow.com/a/9019095/7528396
Note that you can read the remote file and render line by line.

Unable to access file in hard drive using Apache Tomcat server

I'm developing local-only JSP application using Apache Tomcat server. I would like to put a promotion videos on my intro page, but I don't want to move them to webapp folder or anywhere else.
The promotion videos are located:
E:\data\videos\2018...
But writing a JSP/HTML like this wont launch the video, but however it works off-server (launching html from desktop for example, so the path may not be issue?)
<video src="file:///E:/data/videos/2018/promotion1.mp4" controls></video>
Local file links from remote resources are disabled by almost all browsers by default. There are certain possibilities to overcome that, e.g.:
http://kb.mozillazine.org/Links_to_local_pages_do_not_work
https://discourse.mozilla.org/t/opening-links-to-local-files-file/16449/2
To access your static media files from remote page you need to configure your Tomcat server as described here: http://teknosrc.com/access-local-files-static-content-images-videos-media-files-outside-web-application-system-apache-tomcat-server/
solution:
a.) make sure your server is on the same system where the media files are.
b.) If so, you have to create a folder (ex. media) in your application folder inside /src/main/webapp/ and have to put all media files inside a media folder. After that, you can surely access the media files through a server.

How to browse files in server location using Servlet with input type as file?

Can any one help me on the following issue. I have index.html file in that
<td><input type="file" id="testsuitepath1" value="testpath"></td>
By using the above line I am able to browse files from my local system path instead of server path. So ,in Servlets is there any way to access the files by clicking on browse button in the server location.
No, not by default. A web server, at least in part, does what you want - it serves files from the server side. But by default it doesn't let you just browse any file nor see all of the files on the server side. You could write a servlet to do this but you need to be careful to not all the client to access sensitive files.
The .html works at client side. That's why you are able to browse files from local system.
A servlet is delpoyed at server side , So a servlet can access files/resources stored in the web-app that is deployed on that server. This is called accessing relative resources.
Moreover, If you want to access the files from the server via browse button then, you should have the access to the network location where the web-app is deployed.
Later, in the filename(browse window) you can search the path of the server.
e.g: \\web-app\file1.jpg
Personally. I think you have a bad software design issue.

How can i get the path of client side download location in java servlet or jsp?

suppose in my web app user click on download button so a file downloaded into his system. So can i get that client's download location like where the recent downloaded file present in my client system
You cannot get this information.
It is sandboxed, the server will not be informed by the client about the location.
This is not possible since you don't have access to user's file system through the browser (JavaScript).
Maybe using a module or whatever directly in the browser.
You don't. All you get is the file name...
What woule it help you anyway as your server does not have the same structure.

Trigger open&edit file with tomcat WebDav from Java Applet

Currently i have a java applet (with tomcat 6 as backend) that allow users to upload file and download file for document sharing. However, many users forget to upload the edited file back to the server.
Hence, I would like to enhance the applet to allow user to choose a file* for edit and save directly to the web server. Without having the user to save the file to their local harddisk, and upload the file* back to server manually.
After a few goggling, it seems WebDav is the way. I have configure tomcat with the webdav enable in the web.xml, and now i can view file and edit with a Webdav client CyberDuck.
Questions:
is it possible view / edit / lock the file* without installing a webdav client?
Reason is because i have more than 3000 desktop client using the software. Deployment of the webdav is an issue and how do i let each user to access different webdav so they do not see each other's file?
Is it possible to trigger local application to open a file* inside WebDav?
file* = means any file that are able to open from their local machine; examples: ms word, ms excel, ms powerpoint, pdf, PNG, JPG, txt and etc.
Ah, i manage to open it with:
Runtime.getRuntime().exec("winword http://:/xyz/.../pgl_page-bi.doc");
Problem is, every single type of files will need to have a different string inside the .exec(""); not as clean as i expected but at least it works.

Categories

Resources