Hi,
I have been trying to write a servlet which will
upload a file to the
server.For that i used oreilly's MultiPartRequest
class. Iam sending data
through http header from swing interface like that:-
Button.addActionListener(new ActionListener()
{
public void
actionPerformed(ActionEvent e)
{
int returnVal = fc.showOpenDialog(ActionDemo4.this);
if (returnVal ==
JFileChooser.APPROVE_OPTION) {
File file =
fc.getSelectedFile();
String
aa=file.getAbsolutePath();
textArea3.append(aa);
textArea2.append("Local URL:");
long
l=file.length();
try
{
byte buff[]=new byte[(int)file.length()];
InputStream fileIn=new FileInputStream(aa);
int i=fileIn.read(buff);
String conffile=new String(buff);
url = new URL
("http://127.0.0.1:7001/FileUpload?x="+str1);
urlConn = url.openConnection();
urlConn.setDoInput (true);
urlConn.setDoOutput (true);
urlConn.setUseCaches (false);
urlConn.setRequestProperty("Content-Type","multipart/form-data;boundary=---
--------------------------7d01ecf406a6");
printout = new DataOutputStream
(urlConn.getOutputStream ());
String
content="-----------------------------7d01ecf406a6\r\n"+"Content-
Disposition: form-data;"+"name=\"upload\";
filename=\""+aa+"\"\r\n"+"Content-Type:
text/plain\r\n\r\n\r\n"+conffile+"-
----------------------------7d01ecf406a6--\r\n";
printout.writeBytes(content);
printout.flush ();
printout.close ();
But i get the following exception:
----------------------------------
java.io.IOException: Corrupt form data: no leading
boundary
at com.oreilly.servlet.MultipartRequest.readRequest
(MultipartRequest.java:361)
at
com.oreilly.servlet.MultipartRequest.<init>(MultipartRequest.java:149)
at FileUpload.doPost(FileUpload.java:23)
at
javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at
javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet
(ServletStubImpl.java:213)
at
weblogic.servlet.internal.WebAppServletContext.invokeServlet
(WebAppServletContext.java:1265)
at
weblogic.servlet.internal.ServletRequestImpl.execute
(ServletRequestImpl.java:1622)
at
weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
at
weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
Plz guide me where i done a mistake.
Regards
Bikash
__________________________________________________
Do You Yahoo!?
Buy the perfect holiday gifts at Yahoo! Shopping.
http://shopping.yahoo.com
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html