aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Illegal Argument exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Illegal Argument exception" Watch "Illegal Argument exception" New topic
Author

Illegal Argument exception

Amarendra Thakur
Greenhorn

Joined: Feb 16, 2006
Posts: 1
Hi All,

i am using oreilly pacakage for file file uploading i am uploading the saving it in the directory specified in dirName. while uploading i am getting the java.lang.illegalargumentexception at the following line

MultipartRequest multi = new MultipartRequest(request,dirName,10*1024*1024);



//import BACKUP.*;

import java.io.*;
import java.util.Enumeration;
import javax.servlet.*;
import javax.servlet.http.*;

import com.oreilly.servlet.MultipartRequest;
import com.oreilly.servlet.multipart.DefaultFileRenamePolicy;

public class myfile extends HttpServlet
{


String dirName;
String filename;
String filesize;
String lineSep="/n";
String userid;
String jobid;
File myfile;
String docName;

public void init(ServletConfig config) throws ServletException
{

dirName = config.getInitParameter("uploadDir");

System.out.println("the directory name is" +dirName);
}

public void doPost(HttpServletRequest request,HttpServletResponse res) throws ServletException,IOException
{
/*Capturing the Information */
res.setContentType("text/html");
PrintWriter out = res.getWriter();

userid = req.getParameter("userId");
System.out.println(userid);

jobid = req.getParameter("jobId");
System.out.println(jobid);

docName = req.getParameter("docName");
System.out.println(docName);

try
{
System.out.println("the line before ");
MultipartRequest multi = new MultipartRequest(request,dirName,10*1024*1024);
System.out.println("the line after ");

filename = multi.getParameter("fname");
System.out.println(filename);

filesize = multi.getParameter("fsize");
myfile = multi.getFile(filename);

System.out.println(myfile);

System.out.println(filesize);
}

catch(IOException e)
{
System.out.println(e);
}

/* Storing the file related information*/

try
{
File temp= new File("C:/Amarendra/HPUPD","test.txt");
boolean ch=temp.createNewFile();
if(ch)
{

}
else
{
System.out.println("file Not created");
}
PrintWriter p = new PrintWriter(new BufferedWriter(new FileWriter("myfile.txt",true)));

p.close();

FileWriter fos = new FileWriter(temp, true);
BufferedWriter bw = new BufferedWriter(fos);
PrintWriter pw = new PrintWriter(fos);

pw.print(lineSep );
pw.print(filename);
pw.print(filesize);
pw.print(myfile);
pw.print(userid);
pw.print(jobid);
pw.print(docName);
pw.close();


//Rename ren = new Rename();
//ren.rename();

System.out.println("done");

/*Renaming the File*/

File directory = new File("C:/Amarendra/HPUPD");

String[] textFileNames = directory.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".tmp");
}
});

for (int i = 0; i < textFileNames.length; ++i)
{
File oldFile = new File(textFileNames[i]);
System.out.println(oldFile);

System.out.println("This is not yet Done");

File newFile = new File(textFileNames[i].substring(0,textFileNames[i].length() - 4) +".prn");
oldFile.renameTo(newFile);
System.out.println("Renaming is Done");
System.out.println(newFile);

PrintWriter p1 = new PrintWriter(new BufferedWriter(new FileWriter(newFile,true)));

p1.close();
}
}
catch(IOException e)
{
System.out.println(e);
}
}
}




this is the exception which i am getting plz help me as i am clueless.

2006-02-16 17:07:37 StandardWrapperValve[myfile]: Servlet.service() for servlet myfile threw exception
java.lang.IllegalArgumentException
at javax.servlet.http.HttpUtils.parseName(HttpUtils.java:283)
at javax.servlet.http.HttpUtils.parseQueryString(HttpUtils.java:152)
at com.oreilly.servlet.MultipartRequest.<init>(MultipartRequest.java:230)
at com.oreilly.servlet.MultipartRequest.<init>(MultipartRequest.java:109)
at myfile.doPost(myfile.java:50)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:594)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
at java.lang.Thread.run(Thread.java:536)


thanks.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Are you passing parameters to your query ?
Make sure that it does contain key=value, for example:
/myfile?userId=bob&jobId=j1&docName=mydoc

If there are some empty values, I'm not sure that it will work.
[ February 16, 2006: Message edited by: Satou kurinosuke ]

[My Blog]
All roads lead to JavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Illegal Argument exception