473,386 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Tomcat write directory of received files????

Hi everyone,
I am trying to send files with multipart/form-date. Everything is ok
with the send.
But when I am receiving the files I should specify a directory where
the files to be saved. The problem is that Tomcat saves the files into
%CATALINA_HOME%/bin directory. I am wondering why? Why not into my
application directory?
The application directory is %CATALINA_HOME%/webapps/picture.
As a parameter of directory I am giving "." – which means – the same
directory.
Is there another solution except giving directory
"../webapps/pictures"

Here is the jsp code that sends the files.

<%@ page contentType="text/html; charset=windows-1251" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1251">
<title>Send Multiple</title>
<body>
<h1>Page for sending files:</h1>
<form name="send" action="receive.jsp" method="post"
enctype="multipart/form-data">
<input type="text" name="text" value="Tova e text">
<p>
<input name="file1" type="file" id="file1">
</p>
<p> <input type="file" name="file2">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>

Here is the jsp code that receives the files:

<%@ page contentType="text/html; charset=windows-1251" errorPage=""
%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%--@ page import="com.oreilly.servlet.*"--%>
<%--@ page import="com.oreilly.servlet.multipart.*"--%>
<%@ page import="com.oreilly.servlet.MultipartRequest"%>
<%@ page import="org.apache.commons.fileupload.*"%>
<%@ page import="com.oreilly.servlet.multipart.DefaultFileR enamePolicy"
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1251">
<title>Receive</title>
</head>
<body>
<h1>Receive page:</h1>
<%
String dir = request.getContextPath();
MultipartRequest multi = new MultipartRequest(request,".");
// the problem is what to specify here insetead ".", or what to do
with
// TOMCAT to save in my application directory??????
Enumeration fnames = multi.getFileNames();
while(fnames.hasMoreElements()){
String name = (String)fnames.nextElement();
out.println(name);
}

boolean isMultipart = FileUpload.isMultipartContent(request);
/* - another package for multipart/form-date … using
.../webapps/picture/images
DiskFileUpload upload = new DiskFileUpload();

List items = upload.parseRequest(request);
Iterator itr = items.iterator();

while(itr.hasNext()) {
FileItem item = (FileItem) itr.next();

// check if the current item is a form field or an uploaded
file
if(item.isFormField()) {

// get the name of the field
String fieldName = item.getFieldName();
out.println(fieldName+" "+item.getString());

// if it is name, we can set it in request to thank the user
if(fieldName.equals("name"))
request.setAttribute("msg", "Thank You: " +
item.getString());

} else {
// fullFile.getName().
out.println(item.getFieldName()+" "+item.getName());
try{
String filename = item.getName();
//out.println(filename);
//Check if the file exist
if(filename!=null&&item.getSize()>0){
File fullFile = new File(item.getName());
//File savedFile = new
File(getServletContext().getRealPath("/"),fullFile.getName());
File savedFile = new
File("../webapps/picture/images",fullFile.getName());
item.write(savedFile);
}
else out.println("No such file:
"+item.getName());//File not specified
}catch(Exception e){out.println("Exception: "+e);}
}
}
*/
%>

</body>
</html>

If anybody could help I would be THANKFUL.
Jul 17 '05 #1
1 7095
"jajoo" <ji*****@abv.bg> wrote in message
news:2b*************************@posting.google.co m...
Hi everyone,
I am trying to send files with multipart/form-date. Everything is ok
with the send.
But when I am receiving the files I should specify a directory where
the files to be saved. The problem is that Tomcat saves the files into
%CATALINA_HOME%/bin directory. I am wondering why? Why not into my
application directory?
The application directory is %CATALINA_HOME%/webapps/picture.
As a parameter of directory I am giving "." - which means - the same
directory.
Is there another solution except giving directory
"../webapps/pictures"


Tomcat is an application like any other. Any file operations it performs
will be in its current working directory unless you specify otherwise.
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: javajavalink | last post by:
I am relatively new to java and have already tried many ways to write to text files with Java. Is there any way to write to a text file without overwriting what is already there??
6
by: ganderso | last post by:
Help!! I need to interrogate about 150,000 files across a WAN and pull in ONLY the files less than 5 days old and larger than 10k bytes. I'm currently using Directory.GetFiles and it's taking...
5
by: Bas Hendriks | last post by:
Has anyone any idea how asp.net find it's files back after compiling them to the temporary asp.net directory? I found on numerous webpages that the directorynames are chosen random but cannot find...
2
by: James | last post by:
Hi all, I am new to ASP.NET. I am currently working on a project with VB, .NET 1.1 on a Windows 2000 server. I have two files C:\Inetpub\wwwroot\test\test.aspx...
2
by: AppleBag | last post by:
Hello everybody, I am beginning the .NET learning curve, and I have learned how to load a listbox with a directory list of files using this code: If FolderBrowserDialog1.ShowDialog() =...
4
by: Tim | last post by:
Can someone please tell me how I can get the last file added to a directory ( I am assuming it is a file attribute). I have built a text parsing application. Right now I have to manually get the...
2
by: Zytan | last post by:
You can download them here: http://msdn2.microsoft.com/en-us/vstudio/aa718338.aspx This snippet seems wrong: Visual C# 2005 Code Snippets -filesystem -Search a Directory for Files Recursively ...
2
by: vikramb | last post by:
HI Iam working on a task in which i need to refresh the tomcat cache with out restarting it when there is any new entry in the properties file , My question is in the server.xml if...
1
by: Claire | last post by:
Ive written a small string resource building utility that I send out to our translators. I have a setup project for each language we support, which picks out a group of 12 english resx files plus...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.