java上传问题,求各位高手帮帮忙,看看是什么问题,急!急!急!

Java代码如下:

      

package xiazai;

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.commons.fileupload.*;
public class upload extends HttpServlet {
private String uploadPath = "D://upload"; // 上传文件的目录
private String tempPath = "D://uploadtmp"; // 临时文件目录
 public void doPost1(HttpServletRequest request,
        HttpServletResponse response)throws IOException, ServletException
  {
  
  }

public void doPost(HttpServletRequest request,
  HttpServletResponse response)
  throws IOException, ServletException
  {
  try {
  DiskFileUpload fu = new DiskFileUpload();
  // 设置最大文件尺寸,这里是4MB
  fu.setSizeMax(4194304);
  // 设置缓冲区大小,这里是4kb
  fu.setSizeThreshold(4096);
  // 设置临时目录:
  fu.setRepositoryPath(tempPath);
  // 得到所有的文件:
  List fileItems = fu.parseRequest(request);
  Iterator i = fileItems.iterator();
  // 依次处理每一个文件:
  while(i.hasNext()) {
  FileItem fi = (FileItem)i.next();
  // 获得文件名,这个文件名包括路径:
  String fileName = fi.getName();
  // 在这里可以记录用户和文件信息
  // ...
  // 写入文件,暂定文件名为a.txt,可以从fileName中提取文件名:
  fi.write(new File(uploadPath + "a.txt"));
  }
  }
  catch(Exception e) {
  // 可以跳转出错页面
  }
  }
 
  public void init() throws ServletException {
  uploadPath = "D://图片";
  tempPath = "D://图片";
  // 文件夹不存在就自动创建:
  if(!new File(uploadPath).isDirectory())
   new File(uploadPath).mkdirs();
  if(!new File(tempPath).isDirectory())
   new File(tempPath).mkdirs();
  }
}

 

 

页面代码如下:

 

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'index.jsp' starting page</title>
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->
  </head>
 
  <body>
   <form action="fileupload" method="post"enctype="multipart/form-data" name="form1">
<input type="file" name="file">
<input type="submit" name="Submit" value="upload">
</form>
  
  </body>
</html>

 

 

web代码如下:

 

 

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">


<web-app>
<servlet>
 <servlet-name>upload</servlet-name>
 <servlet-class>upload</servlet-class>
</servlet>

<servlet-mapping>
 <servlet-name>upload</servlet-name>
 <url-pattern>/fileupload</url-pattern>
</servlet-mapping>
</web-app>

 

运行结果如下图:

 

 

 

页面结果:

type Status report

message Servlet upload is not available

 description The requested resource (Servlet upload is not available) is not available.

 

控制台结果:

 

严重: Error loading WebappClassLoader
  delegate: false
  repositories:
    /WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@cdedfd
 upload
java.lang.ClassNotFoundException: upload
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
 at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1083)
 at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:806)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
 at java.lang.Thread.run(Unknown Source)
2011-3-15 15:17:20 org.apache.catalina.core.StandardWrapperValve invoke
严重: Allocate exception for servlet upload
java.lang.ClassNotFoundException: upload
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
 at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1083)
 at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:806)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
 at java.lang.Thread.run(Unknown Source)

  • 0
    点赞
  • 0
    收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
评论

打赏作者

yoyo0051

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值