Task: Copy Folder and contents from one vdi to another vdi. This application is internally facing within the company.
Method:
In jsp have user browse for folder
The folder selection is in a text box, the folder path is passed into an action class
The folder path is placed into a teradata table
A script is called to query the table for the source path and target path (pre-determined) and make the copy
Due Dilligence: So far I have tried the <input type="file", which selects a file, not a folder. Also, the file path is not passed through due to security reasons. I have read other possible solutions but none work.
Question: Are sevlets a viable solution, and if so, how do I create one?
I'm going to go with no. There are several reasons for this.
A Java Enterprise Edition application (be it a Servlet or Java Server Page) is not supposed to access the file system directly.
It is inherently unsafe to expose internal infrastructure through an external website.
I think you need to break it up a bit more.
Save a list of shares the server has access to in a data store of some sort, like a new teradata table or for a quick proof of concept plain text file (if you're on Linux you can use the output of something like showmount -e localhost).
Let the user pick the src share from a combobox or something similar.
Continue from your step 2.
This gives you two immediately obviously advantages, which may or may not be relevant.
You can use the system without having access to the physical shares.
You can add metadata (like description or aliases).
Related
For a company internal webapp I need a way to access the full path of files on our internal fileserver that the user drag n drops on a dropzone on the website. As the fileserver is mounted in a similar manner on the webserver the path will point to the same file on its side and I can further process the files.
As that is not possible with plain HTML/Java-Script because of security reasons I did some research and it seems, that one viable way to accomplish this would be to embed a java-applet in the HTML code of the website. However .. as this would be my first encounter with java I'd like to confirm if that is actually possible before starting out.
Or alternatively another way to accomplish this task.
We have developed a web application using JSP and Servlet. The server we use is Tomcat 7. We have hired a host (Daily Razor) with "private JVM" to launch the application in production level.
Now, in our application, user can visit a particular form, browse for a file in his PC and upload it to the server. But I have a question there; what is the best place to store these files? Mainly there are 3 types of files so we would like to categorize them into, "Office', "Home" and "Other" and create 3 folders for them. But inside which main folder these 3 folders should be made?
The main important this is that these files should not be accessed via a URL (because then anyone can get them ), but a Servlet can. Apart from that, the location (String) should be saved in our MySQL database so the file can be accessed again without an issue.
We have developed the application using Netbeans IDE so the folder structure is like below.
I look forward for your answers.
Use a java property to specify the directory where the files should be stored, and pass it on to tomcat during start up.
Also, it might be a good idea to separate the files per user.
Possible Solution:
-Duser.data.export.dir=D:\users_export\directory
In your java code, read the property
String property = System.getProperty("user.data.export.dir");
Now lets say for user 'A'
String userName = getCurrentUser();
Path userDirHome = Paths.get(property, userName, "Home");<br/>
Now use userDirHome to store the data.
Suggestion: When you store the file location in the DB, ensure that you do not store the complete path, only store the relative path, like "Home/myFile.txt".
This will help you at a later point in time when, there is any change in the directory where the file are stored.
I am creating a series of websites that will share a common java code base but will each have a different look and feel, as well as make slightly different calls to a database. Each site will have a unique URL (www.siteA.com, www.siteB.com).
The necessary database information is stored in properties files that appear to be loaded when the applications are deployed (to a JBoss 4.2.3 server). The CSS and images are in static folders.
What I want:
The user enters www.siteA.com
The "unbranded" site is initialized
Java (or whatever needs to) checks the URL to see which files to load
siteA.properties and siteA.css are loaded from the siteA resources folder
siteA's customized site is served to the client
If www.siteB.com is entered, all of its info would be loaded. When I want to add a new Site C, I will just create a siteC resources folder, put the SiteC versions of properties and CSS in it, and the underlying common code should take care of noticing that www.siteC.com was entered and grab from the new folder. All of this should happen without having to redeploy any of the elements common to all the sites.
I think I've mostly figured out how to get the CSS/images side of this working, but I can't get the properties files loaded this way.
Is this even possible? I haven't even been able to find a high-level discussion of the process.
Why don't you look up the HOST http header and output the relevant information for each server using a PHP script. You can output common content using file from an HTML file stored somewhere on the server.
I have a small java utility application which performs tasks on remote computers. This app will provide user with a dropdown/combobox where they can enter ip address or hostnames for the computers they wish to connect to. It would be nice if the users could have a history of items/hosts they had connected in the dropdown.
I thought that I can create a file inside the distributable jar and use it to maintain the history. But writing to a file inside the jar seems to be impossible? The alternate approaches would be to use text files, databases etc located outside the jar. But this is not quite I would like to do as my utility app is only one file and I would like it to be completely independent of any external files. Also its not nice to have a text file stick around your jar file or create a text file each time your app is run.
Considering this case what options can I use? Are there any apis that can help in storing or keeping history?
Why don't you store this info with an hidden file in the user home directory? Many application do the same thing.
You can get the user home directory in this way
String userhome = System.getProperty("user.home");
I'd recommend keeping some .dat file somewhere associated with the JAR. Could be in same directory, or in the user's home (as #dash1e recommends) to avoid any permissions issues. I think you'll find that's the simplest solution.
Another option would be to use a Java-based database solution which could be bundled into your JAR (see Apache Derby, et al). Note that this would create files somewhere, but you wouldn't have to worry about the file-level management, as you'd just be interacting with it as a database.
One final option, if you really insist on avoiding having to maintain your own file, would be to use the Java Preferences API which provides an OS-agnostic way of storing data on the system in some obfuscated location. This is arguably a bit of a misuse of the goal of this API, but would accomplish what you're asking for.
I have developed a command-line (read: no GUI) Java application which crunches through numbers based on a given dataset and a series of parameters; and spits out a series of HTML files as resultant reports. These reports hold a large amount of data in tables, so in order to give the users a easy and quick overview of the results, I utilized the JUNG2 library and created a nice graph.
Here's where it gets interesting; since I would like the graph to be interactive it should be deployed after the application has run and files are generated, whenever the user wants to view the reports. I decided to go with an applet based deployment, however I am not too happy with the current setup due to the following reasons:
I want to make the software as simple to use as possible (my users won't be tech-savvy, and even tech-intimidated in most cases). I would really like to distribute one JAR only, which forced me to put the applet with everything else it needs in a package in the same JAR as the main application.
The applet and the main application need to communicate the results, so I create a xML-based report which is used to hold information. As long as the files are on a local machine and are not moved around it all works fine. Unfortunately I also need the files to be moved around. A user should be able to take the "results" folder to a USB stick, go anywhere plug the stick to another computer and be able to use the report as he/she likes.
For the time being the applets are implemented with the following html code:
<applet code="package.myapp.visualization.GraphApplet.class"
codebase="file:/home/user/myApp"
archive="myApp-0.2.6-r28.jar"
width="750" height="750">
<param name=input value="results/test_name/results.fxml">
</applet>
As you can see this applet will not work if the parent folder is moved to another location.
As far as I know I have a couple of alternatives:
a) Change codebase to point to an URL on our webserver where I could put the jar file. This however creates the problem with permissions, as the applet will not be able to read the results file. Alternative is to upload the results file to the server when the user wants to visualize the graph, although I am not sure if that's a good option due to server security and also if it could be made so that upload happens automatically without bothering the user.
b) I can use a relative path on the codebase attribute, but then the whole folder hierarchy needs to be intact upon copy. This could be a last resort, if I cant come up with a better way to do it.
c) change the deployment method (would like to avoid this alternative to not spend more time on the development phase)
Any ideas? Am I missing something? How could I tackle this problem?
Thanks,
I'm not sure I entirely understand your use-case, but from what I do understand, I would suggest this:
Dump the applet for an application launched using Java Web Start. Have the JNLP file declare a file association for the fxml file type. When the user double clicks an fxml file, it will be passed as an argument to the main(String[]) of the JWS application.
A sand-boxed JWS application can gain access to resources on the local file system using the JNLP API. Here is my demo. of the JNLP API file services.