可能是String myUrl=request.getRequestURI();有问题,你把myUrl输出,看看是否跟你想象的值一样

解决方案 »

  1.   

    加一个处理异常过程:
    try{
        String myUrl=request.getRequestURI();
        URL url=new URL(myUrl);
        String myPath=url.getPath();
    }
    catch(MalformedURLException e){}
      

  2.   

    myUrl的型式应该是http://www.csdn.net/expert
      

  3.   

    myUrl 应该写全 如  http://java.sun.com/index.html
     
      

  4.   

    同意楼上,给你一个方法,用它来转化
    如果用url调硬盘上的一个文件也需要用file://...
       public static final URL createURL(String fileName) throws Exception
       {
          URL url = null;
          try
          {
             url = new URL(fileName);
          }
          catch (MalformedURLException ex)
          {
             File f = new File(fileName);
             try
             {
                String path = f.getAbsolutePath();
                String fs = System.getProperty("file.separator");
                if (fs.length() == 1)
                {
                   char sep = fs.charAt(0);
                   if (sep != '/')
                      path = path.replace(sep, '/');
                   if (path.charAt(0) != '/')
                      path = '/' + path;
                }
                path = "file://" + path;
                url = new URL(path);
             }
             catch (MalformedURLException e)
             {
                System.out.println("Cannot create url for: " + fileName);
                throw new Exception(e.getMessage());
             }
          }
          return url;
       }