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.
Related
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.
I have an android application, which wants the user to login each time he runs the app. So, the login procedure is simple, using the sqlite dabase file i'm using. I've copied the file in assets folder and doing the necessary modifications. But, the database file is of no use unless it is on the server. I don't have any server so i'm thinkin of keeping the database file on dropbox, google drive etc and then read or update that file as per user commands. The question is how to do that? I was searching the web for it, and found that the only way is downloading the db file modifying it and the uploading it back. Can anyone give me an example??
Doing that isn't possible unless you have a server.
Because, if you are using dropbox, first you'll have to make your file public in order to download it (Not recommended at all. Compromises security). Then you can use the url to download the file. But you won't be able to upload it back (Unless you are able to login to dropbox through your Android code).
Instead if you a web server with MySQL n PHP, you can easily send POST requests to your server.
I have a normal web application which are store user details and their images, we are creating user wise run time folders to store their all profile pictures.
example:- upload/user_1/anyimage.jpg
Also I have another java process(running as thread in server) which we are using to parse user data in bulk and after parsing we save it in database also we are creating run time folder to store user's profile pictures with same file structure.
example:- upload/user_2/anyimage.jpg
Now problem is:- when user 2 wanted to change their profile picture using UI(php application) using move_upload_file()
we are getting permission denied error.
When I have investigate more deeply I found that when folder has created using java application its owner is root and my php application is running under daemon user so that's the reason behind permission denied error.
How to overcome this problem, because we neither can change user who is running php application(because its system backend user) nor my java application.
As I am very new to this forum, please let me know if this is write place for this.
use chmod
chmod('/path/to/folder/, 0755);
if you want to change the ownership use:
$path = "/path/to/folder" ;
$user_name = "root";
// Set the user
chown($path, $user_name);
I'm making an intranet page where the users will put in some information (text). My application will take this text and go through files on a shared drive that the webserver has access to. Based on the text and some logic it'll find the file that matches.
Now that I have the full absolute file path of the matched file, I'd like the users to be able to download the file from the page as well. However, since the file doesn't exist in my application I can't serve it.
All I have is the network share like: \\somenetwork\share\filename.pdf
Is there a way I can let users download this file (with the above path) from the intranet page?
I've tried:
<a href="\\somenetwork\share\filename.pdf"> but that does not work.
also tried prepending file:// but that link does nothing. not even open the file or give the option to download.
PS: I understand that this should ideally be a script on the command line. I'm just trying to turn a command line script into an intranet page.
This works in chrome and ie. For a txt file on a shared drive (that I have access to), it opens the file in the browser.
test
You have to ensure the user has access to the shared drive for this to work.
Otherwise you'll need to host the file somewhere (e.g. via the webserver).
I am trying to create a CSV file dynamically in the user's system whoever uses my Application so that I can write data into it and then import it to an Excel.
Once I am done with my Application, I am deploying the WAR file in the Tomcat Server in the Server system. I am trying to use System.getProperty("user.home") for creating the file in a particular path. But the file is creating in the system where the App is deployed (Server system).
Different users will be using the App in different systems,so how can I get the path for creating a file in the Local Host System (user's system)?
Any help will be appreciated.
Tomcat knows nothing about the user who is opening the web page. Tomcat is using user.home of those user who started the tomcat instance. You should create custom login permissions with session and map your website accounts to local system users.