Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 8th, 2003, 05:54 PM
Registered User
 
Join Date: Jun 2003
Location: Midden Beemster, Noord Holland, Netherlands.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Archanazzar
Default MultipartRequest File Upload

I'm trying for ages to get a working fileupload system with a variable name. I've searched the entire web for a nice (not too difficult) example but there doesn't seems to be one. I've been trying to get a working one and im this far atm. I thought that it should work but i keep getting a weird error. Weird, coz to me its standing there correct. Could anyone tell me what is wrong in this code or supply me with another 'working' version of a fileupload that's understandable for an amateur JSP programmer.

The error i get is this:
Error creating file: java.io.IOException: Posted content type isn't multipart/form-data

Here's my code:

<%@ page language="java" contentType="text/html" import = "java.io.*" import = 'com.oreilly.servlet.*' %>
<%@ page import="com.oreilly.servlet.MultipartRequest" %>
<%@ page import="java.util.*" %>
<html>
<head>
<title>Project Gosu</title>
<%
    String urlred = "loginfailure.htm";
    String name = (String) session.getAttribute( "Sessie" );
    if( name != null )
    {
        out.println( "Hello "+name+"!" );
    }
    if(name == null)
    {
        response.sendRedirect(urlred);
    }
    try
    {
        MultipartRequest mrequest = new MultipartRequest(request, "C:/jakarta-tomcat-3.2.4/webapps/ProjectGosu/Login/Replays");
        Enumeration files = mrequest.getFileNames();

        while(files.hasMoreElements() )
          {
            String upload = (String)files.nextElement();
             String filename = mrequest.getFilesystemName(upload);
            System.out.println(filename);
        }
    }
    catch(Exception ex)
    {
    System.out.println("Error creating file: " + ex );
    }
%>
</head>
<body LINK="#000000" VLINK="#000000" ALINK="#000000">
<table width="984" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="128" colspan="3" bgcolor="F1ECE9"><img height="128" width="1024" src="../Tryout_Pic.jpg"></td>
  </tr>
  <tr>
    <td height="640" width="184" bgcolor="F1ECE9" valign="top">
    <img height="8" width="6" src="Hyperlink_pic.jpg"> <a href="../index.jsp" title="Index">Index</a><br>
    <img height="8" width="6" src="Hyperlink_pic.jpg"> <a href="main.jsp" title="Main">Main</a><br>
    </td>
    <td width="616" height="640" valign="middle">
    <form name="frm" method="post" action="main.jsp" enctype="multipart/form-data">
                <table align="center">
                    <tr>
                        <td>File
                        </td>
                        <td><input type="File" name="myupload">
                        </td>
                    </tr>
                    <tr>
                        <td>
                        </td>
                        <td><input type="submit" value="Insert">
                        </td>
                    </tr>
                </table>
            </form>
        </td>
    <td width="184" height="640" bgcolor="F1ECE9" valign="top" align="center">
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
Reply With Quote
  #2 (permalink)  
Old June 17th, 2003, 10:28 AM
Registered User
 
Join Date: Jun 2003
Location: Hyderabad, Andhra Pradesh, India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

if you now perl cgi then you need a small code to do it .
# !/usr/bin/perl
upload_dir =".";

 $query = new CGI;

 $filename = $query->param("filename");
 $upload_filehandle = $query->upload("filename");
 $filename =~ s/.*[\/\\](.*)/$1/;

 open UPLOADFILE, ">$upload_dir/$filename";

 while ( <$upload_filehandle> )
 {
   print UPLOADFILE;
 }

 close UPLOADFILE;

#this will help you to save the file by $filename
#in the present directory as I have given dot as the
#upload directory the html file will include the form
#tag and the input type=file name=filename and this will
#will give u the desired output

Great floods have flown from simple sources.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Filter File Types in ASP.NET File Upload ramuis78 ASP.NET 2.0 Basics 2 May 31st, 2007 10:50 AM
upload file hansgregory Pro Java 0 April 27th, 2007 09:18 PM
Whole Folder upload(Multi file Upload) ramasamy_rams XML 1 September 9th, 2005 12:43 PM
JSP file upload and delete file pandjie JSP Basics 0 January 29th, 2005 10:49 PM
Upload file hbcontract XML 2 November 6th, 2003 07:54 PM



All times are GMT -4. The time now is 06:00 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.