How to download zip file from tomcat server web app location - java

I am working on ios project. One of the module in that project download *.zip files and extract them into app memory. on the server side I installed tomcat server, and uploaded all *.zip files and some *.txt files to the context path.
But when I call the *.txt file's it's working fine (I am getting text on app and browser) but when I call *.zip's file I got 404 (the requested resource is not available). the url is correct but it's only working for .txt files and some extension files.
I think it's blocking .zip files for security reasons. But I need zip file need to downloaded.

if the .zip files is outside the server webapps path its need to be added on context path (and dir path), and reload the server solves the problem.

Related

How to upload resources files with app to cloud foundry

My project needs to read several files as resource (krb5.conf, truststore, keytab). they are in project directory. e.g. C:\Users\WorkSpace\MyProject\krb5.conf.
However, when I upload my project to cloud foundry, the app cannot find my resource files when running.
This is my first time deploy app on cloud foundry. Is there anyway to upload resources files like text file, image jpg to cloud foundry with project? so app can read those files when running on cloud foundry
When you cf push an application, the cli will upload all files under the specified path. By default, the path is the current directory. You can set a custom path with --path or -p.
The --path and -p argument may also point to zip files or jar files, for Java apps. In that case, the contents of the archive are uploaded.
The only exceptions:
Files listed here.
.cfignore
_darcs
.DS_Store
.git
.gitignore
.hg
manifest.yml
.svn
If you have a .cfignore file (same syntax as .gitignore), anything matched is not uploaded.
To troubleshoot issues:
Check your path. Make sure it's correct and includes your files.
Make sure the files are not being ignored.
Run cf ssh to your app and check if the files exist.
Ensure you're using the correct path to files in the container, use $HOME or /home/vcap/app which are the root for your application files.

Upload file to payara5 docroot

I've installed payara5 on ubuntu and going to upload file to docroot.i need to know if there is such a capability in payara
Payara doesn't support uploading individual files. It's an application server and supports only uploading whole application packages.
But you can upload files to the docroot manually, e.g. using FTP or SFTP. If you place your files to glassfish/domains/domain1/docroot, they will be served from the root context. E.g., if you upload a file image.jpg to that directory, it will be accessible at http://host:8080/image.jpg

Java application with simple Web Server exported as JAR

I have created a simple Web Server application using Java APIs.
Web server is working as expected and I am able to get the HTML pages in the browser.
I am developing this Java App on a Windows Machine. For testing I am exporting my app as JAR and then testing it on Target Device which is a Linux Box. In my app I have created a "webroot" folder and I am storing all the HTML files, that web server needs to serve.
So when I create JAR file of the app then it has "webroot" folder with all the html files in it. When I run this application on Windows then I am able to get the html pages. But when I run this application on Linux box as a JAR then I am not able to retrieve html files. Also when I copy my "webroot" folder outside the JAR then it works and I am able to see the HTML pages getting delivered in the browser.
So is there any way I can access html pages which are in the jar file itself without copying them outside?
My Project Folder structure is as below:
/src
-com.myprj.server -> contains server Java files
/webroot -> all the html pages
/bin -> jar files as per the above package path
/myprj.jar -> Project jar file
So above jar file has the webroot folder. And from the code I am accessing it as "webroot/FileName.html". If I keep webroot as in the same folder as jar then it does work.
Without seeing how you're actually serving the content, it's hard to say what you're doing wrong, but you can always use Class.getResourceAsStream() to access the resources from the classpath. If you're running it as a jar file, then the contents of the jar file are included in the classpath too.
To serve content outside of the jar file, either include your "webroot" in the classpath, or create some kind of mechanism to first try the classpath and then an outside path.

How to hot deploy newly created files to Apache Tomcat in Eclipse IDE?

I have a peculiar problem. I am extracting the data from a database in the form of .csv file and then passing this file to d3.js for visualization.
The problem is, d3.js doesn't allow file:// based protocol (so I cannot give path to .csv file directly). The .csv file needs to be located on the server. But this file is generated on the run time.
I tried dumping the file in the same project folder, but as expected, the Eclipse doesn't take the updated file until next clean and build action.
Any idea how to work around this problem?
You need to place the file in the place where your application is deployed on Tomcat (e.g.: Tomact7\webapps\myProject...), not in Eclipse Workspace location, this way your js can access the File either by its URL or relative path.

Tomcat 404 for a folder in webapps

I have a folder called attachments in my webapps folder in my Apache Tomcat directory, in which I need to save some files and images. When I'm giving the local path i.e. in C:/ the files needed are being saved in the correct location.
However I need to load these images from the server at runtime so I'm trying to access the image by the localhost url /attachments/img.png. The image is not being found (404 error).
I tried opening Tomcat's manager to see if attachments is listed. It is there however when I click it a 404 error is being thrown too. Other deployed web applications are being found.
What could be the cause of this?
You cannot just create a folder in $CATALINA_HOME/webapps like this and access it from web browser.
webapps folder is supposed to be home for all web applications with proper J2EE web app like directory structure e.g. WEB-INF/web.xml, WEB-INF/classes, WEB-INF/lib, META-INF etc.
Read more about Web Application Directory Stricture

Categories

Resources