Publish a locally generated report on the server - java

I have my web application running using a tomcat server on localhost:8080/myWebApp
Internally I accomplish a task of creating a report which is stored locally at "C:/project/myProject".
I can view the report by opening "C:/project/myProject/report.html" manually. I want to integrate this into my web application.
I tried writing a jsp file to open this "report.html" but that does not seem to work.
myJsp.jsp
<a href='file:///C:/project/myProject/report.html'>View Report</a>
This doesnt work.
Edit: I do not want to store the report in my webapp directory because it will be deleted when I build the new .war file and deploy it.

I think you access the webpage is not from localhost.
the problem is
<a href='file:///C:/project/myProject/report.html'>View Report</a>
href is relative to the machine which access from (using the brower). so if access in localhost, you can get resource from file:///C:/project/myProject/report.html , but from some other machine , the resource file:///C:/project/myProject/report.html is not able to touch.
if you want to access the resource , you can easily publish content in web by any web server (nginx/apache/IIS/tomcat) or some file content service, and point the href there

Either put that in your current application folder and access directly
<a href='report.html'>View Report</a>
Or go to that folder path using:
<a href='../../report.html'>View Report</a>
or try using your ip:
<a href='http://<ip address>:<port>/<folder_path>/report.html'>View Report</a>

Related

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.

Unable to open the link after file upload in struts2

I am performing a task in Java Struts2 Framework. Task is uploading a file and view the file when click on a specific link.
Problem is I am able to upload the file in desired folder. But when click on link It is giving 404 error, although file is uploaded in correct location as in link.
If I refresh project, then I am able to see the file on same link.
Without refreshing project, Can we see the file in browser in STRUTS2 framework?
Thanks
If you are running a server in eclipse then it may be resolved when you deploy it on the Apache Tomcat Server because when you run on internally all data stored in the cache memory which is temporary while the server is running once you stop the server you will lose your data.
You just create the method to open the uploaded file, and use () tag to instead of anchor tag for Link and call the action mapped with file opening method. In method you just write the code to open the file on client computer.

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 to get client files in Java bean?

I develop a web application using JDeveloper. Then, my scenario is I want to get a file from client directory (e.g. C://Image.jpg). What I want to achieve is the client's directory defined programmatically. So, I used InputStream, but it will search a file in server directory. if I used UploadedFile, I don't know how to define it. Note that I don't want to use InputFile.
Does anyone have a solution for me?
Search for HTTP File Upload. You need an <input type='file'> control on your webpage, and form encoding set as enctype='multipart/form-data'.
Generally, you can't control the default directory where the browser is going to open a file chooser -- it normally starts from the "user home" directory, but other dirs can be navigated to.

J2EE: file access from web server.

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.

Categories

Resources