当前位置: 代码迷 >> Java Web开发 >> jspSmartUpload实现文件上传 代码没有提示异常但是运行时会出现404异常 The requested resource is not avai
  详细解决方案

jspSmartUpload实现文件上传 代码没有提示异常但是运行时会出现404异常 The requested resource is not avai

热度:173   发布时间:2016-04-17 10:33:49.0
jspSmartUpload实现文件上传 代码没有提示错误但是运行时会出现404错误 The requested resource is not avai
前台jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>jspSmartUpload组件文件上传</title>
</head>

<body>
<font size="+5" color="#009933"><b>jspSmartUpload组件文件上传</b></font><br />
<form name="uploadForm" enctype="multipart/form-data" method="post" action="SmartUploadServlet">
<table border="0" align="center" cellpadding="2" cellspacing="2" bgcolor="#FFFAFA">
<input type="hidden" name="paramete" value="OK" />
<tr>
<td>
<div align="center">上传文件1</div>
</td>
<td><div align="center">
<input type="file" name="file1" size="25" maxlength="80" />
</div></td></tr>

<tr>
<td>
<div align="center">上传文件2</div>
</td>
<td><div align="center">
<input type="file" name="file2" size="25" maxlength="80" />
</div></td></tr>
<tr width="100%">
<td>
<div align="center"><input type="submit" value="上传文件">
<input type="reset" value="清除"></div></td></tr>
</table> 
</form>
</body>
</html>

后台的servlet


package lee;



import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.*;
import javax.servlet.*;
import com.jspsmart.upload.*;
import java.io.*;


public class SmartUploadServlet extends HttpServlet {
private ServletConfig config;
//初始化Serblet
final public void init(ServletConfig config)throws ServletException{
this.config=config;
}
//处理get请求
public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
this.doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException{
//获取PrintWriter对象
PrintWriter out=response.getWriter();
out.println("<html>");
out.println("<body bgcolor='write'>");
out.println("<br><h1>jspSmartUpload</h1>");
//新建一个smartupload对象
SmartUpload mySmartUpload=new SmartUpload();
try{
//上传初始化
mySmartUpload.initialize(config, request, response);
//设定每个文件上传的最大长度
mySmartUpload.setMaxFileSize(1*512*1024);
//设定总上传数据的长度
mySmartUpload.setTotalMaxFileSize(1*1024*1024);
//设定语序上传文件的类型,金鱼徐java文件
mySmartUpload.setAllowedFilesList("java");
//设定精致上传的问价类型,进制伤上传带有exe,bat的文件
mySmartUpload.setDeniedFilesList("exe,bat");
//将上传文件全部保存到指定目录
int count=mySmartUpload.save("/");
//利用request对象,获取参数之值
out.println(mySmartUpload.getRequest().getParameter("paramete")+"nbsp"
  相关解决方案