Thanks in advance.
I have a question with regards to Sub-Domain.
the Primary domain is www.abc.com
There is a function in JSP which creates an Image for the user as membership cards which needs to be saved and which is also getting saved in a particular folder.
The concern is that whenever I make any changes on the websites java class files I re-upload the .war file on the server which recreates all the folders and files on the server in turn what happens is that all the Images created for the user also gets deleted.
So if I create a Sub-Domain called www.members.abc.com and create a folder in it where all the created Images will be stored then when I reupload the .war file will this sub-domain and its folders get affected.
Related
What is the correct/proper way to upload files to a server? I'm only talking about small files such as images, text files, and excel/word files.
I know that I can upload images to the database using BLOB. But what about the others?
I have a table called "Ticket" which contains information such as date created, ticket number, caller, attachment, and etc.
I'm having problems on how to upload an attachment to a server.
The first option should be uploading the image to a file server and stored the file id or uuid in your ticket table, or a OneToMany table stores all attachments.
Always void using BLOB to store image binary in database. Database has this capability doesn't mean it's a good way to use it.
If you are working on a small project, you may not see the problem. If the concurrent is relatively high,
Imagine you store the files in the database, even all are just images, whenever you retrieve the tickets, the a-few-MB image will be in the memory. It's a waste of server memory.
If you are using some ORM to retrieve the list, which will be worst and your server can be easily OutOfMemory.
One more thing is that if your system has Web Application Firewall in front, it's also advisable to separate file upload with normal form submission.
On my personal computer, using Eclipse I have developed a java application to allow users to create their profile. In this application user logins which is just sql query based user name & password verification, After successful login user fills a profile form(createprofile.jsp), this form allows user to upload profile picture also, when user submits the form he gets redirected to another jsp(showprofile.jsp) which shows all saved details with uploaded picture.
Here I am saving all the form data in SQL table and uploading the profile picture in a folder D:\UploadedImages.
Tomcat is also running inside Eclipse as localhost, I have added a context entry in Tomcat server.xml, due to which my uploaded files in the above folder are available at url http://localhost:8080/ProjectName/images/imagename.jpg. This helps me to add profile picture in showprofile.jsp like
<img src="http://localhost:8080/ProjectName/images/imagename.jpg">
Now I want to upload this project the hosting server like HelioHost or godaddy. What I am not sure of that if I upload this project, what should be my permanent destination folder on hosting server to upload user profile pictures and how can I make them available at an URL like above.
Please help, thanks in advance.
You need the relative path of the tomcat. catalinaBase is what you actually need. See the below example:
File catalinaBase = new File( System.getProperty( "catalina.base" ) ).getAbsoluteFile();
File propertyFile = new File( catalinaBase, "ProjectName/images/imagename.jpg." );
This should be your path.
If you need something different than this please update you question.
I 've created a servlet to let users download a file . When the file is downloaded , I want it to be ReadOnly so that the user can't modify its content . So I've used the java.io.File class :
downloadFile.setWritable(false);
but I realized that the user can unset the read only flag after downloading the file .
What can I to prevent unsetting the read only flag?
I've created a servlet to let users download a file.
That servlet will be running on the web server. It's not running on the user's local computer - so it can't change anything about the user's local file system. Even your downloadFile.setWritable(false) won't operate on the user's local file system - the file will be saved by the browser, and the user gets to do whatever they want with it.
Even if you are running some app separately to your service, it would be not only hard, but pretty unfriendly to create a file which the user couldn't touch on their own system. You could try to run your app as a separate user, and give appropriate permissions to both the file and the directory it runs in - but then if the user has access to an administrator account, they'd still be able to override that.
As a user has downloaded your file, he can do anything with this file. If you are concerned about authenticity of the downloaded file, then consider data signing.
Sign your file using key, that is stored on the server and which is not available to end user.
To verify the file authenticity implement a servlet with functionality described in the link above.
How to read and write files from a protected shared folder on another device using Java?
I'm currently working on a backup program which backups all the computers we use at home to a NAS system. This NAS has a shared folder which is used to store the backup files in. This shared folder is protected with a username and password.
I would like to read and write files to this system using Java. Reading and writing files is easy, the problem is though, it isn't possible to read and write files from this shared folder because user credentials are required. How to I login automatically on this shared folder with supplied user credentials using Java, before using this shared folder?
So, the problem doesn't have anything to do with the file path I should be using, or the way I should reach this folder. The problem I have is, that the Java program needs to login automatically on this shared folder with supplied user credentials before reading or writing any files from this external file system.
I am new to Google App Engine. I ran (locally) the sample of GAE bolbstore application given in the below link:
https://developers.google.com/appengine/docs/java/blobstore/
It launched a page to choose and submit a file. When I choose a file clicked the submit button:
i) the browser automatically downloads the same file. Why is it again downloading the same file?
ii) it created two files inside the folder 'appengine-generated'. They are:
d06-XwWoSZVw9HRcnLjZiA
local_db.bin
What are these files and where did my file store as blob?
Don't worry too much about what happens locally on the dev server.
i) It's just part of the demo, it serves you back the file you just uploaded because of this line:
res.sendRedirect("/serve?blob-key=" + blobKey.getKeyString());
ii) The first would I guess be the file you've just uploaded, the second would be the local copy of mySQL the dev server is using to emulate the datastore itself. Try comparing sizes to the original file you uploaded?
Once you have stored the file you have to access it via the api's provided, what form and where the file is actually stored no longer matters.