Tomcat write directory of received files????

From: jajoo (jivkoto_at_abv.bg)
Date: 01/27/04


Date: 27 Jan 2004 04:11:09 -0800

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.DefaultFileRenamePolicy"
%>
<!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.



Relevant Pages

  • A struts 2 label error
    ... Below is my JSP code. ... Preview it in tomcat, an error comes out. ...
    (comp.lang.java.programmer)
  • Re: Me and David C. Ullrich
    ... the flipper ... >wouldn't have had to invent the statement to have made it. ... >> obligated to specify them and also the rules by which they would be ... could have been said besides "there is at least one head". ...
    (sci.math)
  • Re: Specify Size on Pictures
    ... Are you checking HTML View to see it the value is in the code, instead of just looking at the image ... FrontPage Resources, WebCircle, MS KB Quick Links, etc. ... > before this download is completed. ... > To specify the image size in FP2000, I check the box at Picture Properties ...
    (microsoft.public.frontpage.client)
  • Re: RSS feeds and HTML special characters
    ... to specify somewhere that the HTML document should be rendered as ... It's an important principle (see RFC2070 for the original ... character which is outside of the chosen character encoding. ... the old MIME terminology uses the attribute name "charset" to specify ...
    (comp.lang.perl.misc)
  • Re: Footer on page with fixed height
    ... The containing block in which the root element lives is a rectangle with the dimensions of the viewport, anchored at the canvas origin for continuous media, and the page area for paged media. ... If percentage value is specified for div, the percentage is taken form its containing block. ... The same holds true for html, except that html is the root element, has no container and its 100% height is that of the full viewport. ... If at least one of them does not specify a percentage, the div height will be its content. ...
    (comp.infosystems.www.authoring.stylesheets)