java tomcat application variables - java

I'm quite new to full stack java web app developement. I developed an app which deals with files uploads by the user to the server. My question is:
How to set, particularly the server-side storage path?
To be more exhaustive, I developed my project as a Java Web project in Netbeans (no Maven). I deployed the .warfile on the remote server and everything works fine, but, as I developed the app locally, I have a storage path set to c:\..., and I want it more like /opt/tomcat8/...
So, as the .war way is simple to operate, but also "blackboxed", how should I do ? Is that possible to specify parameters in an external file, for example ?

Related

Where to upload an image/file to make it appear on HTML?

Well,I'm working on an Eclipse Dynamic Web Project under Tomcat.
I'm trying to make a web application/site.In a jsp/html page,there is a form where a user can upload a photo.
I handle then this action from a servlet that has to store this image/file somewhere so as to make it possible the image appears whenever I want on the site.
Here is the problem.I started by storing it on my file system,(path in a database) but when I wanted to retrieve it the page didn't appear.
I guess the reason is here:
Why can't I do <img src="C:/localfile.jpg">?
Then,I tried to store the file in the eclipse project folder(WebContent/folder) where I've stored manually some images that do appear.
File folder=new File("/TED/res/img");
File file=new File(folder,fileName);
System.out.println(file.toPath());
Files.copy(fileContent, file.toPath());
But this exception happens:
java.nio.file.NoSuchFileException: /TED/res/img/2017-08-13-123524.jpg
It's one the line of files.copy command which means that
new File(folder,fileName) that I tried failed
What should I do? From what I've read,I understood that also saving file in the IDE's project folder is also wrong but what other choice do I have?
Ultimately, the project will be deployed to a server. As such, there are three distinct issues:
Uploaded user content location: content like images should be uploaded to a folder outside your web app (project). Images inside the web app (project) should be those that are necessary for the application and provided by the developer, not user-generated.
In Eclipse, during development and testing, you will want to serve these images through Tomcat. There are many ways to do this. Tomcat configuration is probably not the best for this - please read the answer and discussion here: Simplest way to serve static data from outside the application server in a Java web application
Once the application is deployed to the server, Tomcat will most likely run behind a Web server like Apache or Nginx. In this case, the external image folder and its contained files can be served directly by the Web server. Even if you implemented a servlet in (2) for local testing with Eclipse and this servlet is part of the code that is deployed, it will not be invoked as the URL will be intercepted by the Web server before it reaches Tomcat. For example, if your uploaded image folder is C:\images on your development environment, it can be served by the servlet using the technique in (2) as /images/*. When deployed to a server, the Web server can be configured to servet /images/* from /srv/content/images and this request will never reach Tomcat.

How do i publish my Java code to localhost using Tomcat 6?

I'm very new to programming and i'm too lost.
I wrote a simple Java code on Eclipse (2 Classes) without any GUI and i want to access this simple Java App from any device in my LAN using a browser.
According to what i found on Google and Stack Overflow, Tomcat might help me.
Tomcat 7 didn't work on my Eclipse, so i'm using version 6 of it.
How can i make a GUI for my app?
And what do I need to be able to publish it using Tomcat?
Any help will be appreciated.
Thanks Everyone in Advance.
Tomcat is an application server. It means that you can write an application and then deploy it to a server (for example Tomcat). Then this application will be accessible on the server by some URL (for example http://localhost:8080/AwesomeApplication).
It only makes sense for web applications that handle some requests. You can't deploy an application with GUI, or simple console application to Tomcat or any other app server.
In language of final file representing your app - it must be a WAR file.

Java Code in Azure cloud service

I have java code (that generates jasper reports) and I couldn't convert it to .net and I want to run it on a "Cloud Services" how can I run java code into cloud service ?
any help will be appreciated
#Dhana provided a link to a tutorial for pushing a Java app to Azure in Cloud Services (worker role). You could also push to a Web role but it makes less sense since IIS runs in a Web role, and you'll probably want Jetty, Tomcat, or JBoss for your web server.
If you're running a console app, that's fine too - just launch it from a startup script or the OnStart() in your workerrole.cs.
You'll need to install the tooling into Eclipse. At this point, you'll be able to build Azure deployment packages, in a similar way to Visual Studio (The Azure plugin for Eclipse only works on Windows though). Part of the packaging sets up links to the appropriate JVM and web server package, as well as your own jar files.
If, say, you have a console app that listens on a port, you'll just need to make sure you have an input endpoint set up for the port you want to expose.

How to make website live? (From the point of having it as a Spring MVC project in Netbeans)

Silly question as I just started web dev. Consider that I've got the project build on Spring MVC Framework in the Netbeans (a web site). I would like to make it live.
What is the actual process of making it live considering the fact that I bought the domain and got the hosting? i.e. you upload project in the repository of hosting provider? (not sure if the question is correct, hence correct me if it's wrong)
Can I somehow connect the repository of hosting provider with my Netbeans to update my web site directly from it? (like it works f.e. with svn repository)
First of all, it's a java application that you want to host / publish, so you will need java hosting company.
You need domainname, you can buy one, or get free domainname (there's a few options, you can get free .tk domain, some hosts offer free domain with 1 year prepay as well).
Yes you can connect to your host's SVN with your Netbeans IDE. But deployment process depends on how you will set up your environment on host side. SVN is a place where you keep your source code, not a compiled java application. You can use your host's SVN server, but then still you need to compile java code and build war file which you can deploy under your java server. Some java hosting companies offer Apache Maven, which can helps in your case. Another solution is to build war locally, and upload ready app to your java host account (try to use SFTP or SCP, most of java hosting companies offer SSH access to your account, try to avoid FTP as it's pretty unsecure).

how to access files on local file system from deployed web app?

I have a web app deployed on Tomcat on Windows 7. I have various files on the PC, local file system, that I want to access from my web app. How can I do this or is this possible?
Ok, looks like I found the solution.
Can just use the File() object with absolute paths and that does the trick.
I thought there would be some special requirements for web apps but it looks like there isn't

Categories