我正在尝试上传文件和文本字段。虽然据说我无法使用request.getParameter("remarks");
检索文本字段的值,但我导入了commons-fileupload
。虽然我似乎无法弄清楚我的代码有什么问题,但这行中有错误List<FileItem> items = upload.parseRequest(request);
说SEVERE: Servlet.service() for servlet [SubmitResult] in context with path [/HIS] threw exception [Servlet execution threw an exception] with root cause
java.lang.ClassNotFoundException: org.apache.commons.io.IOUtils
HTML:
<div class="modal-body">
<input type="hidden" name="orderid2" id="orderid2">
<table>
<tr>
<td>
Remarks:
</td>
<td>
<input type="text" name="remarks" placeholder="Remarks" autocomplete="off" class="form-control placeholder-no-fix"> <br>
</td>
</tr>
<tr>
<td>
Upload File:
</td>
<td>
<input type="file" name="file" id="file" accept="image/png, .txt, application/pdf, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/msword"/> <br>
</td>
</tr>
</table>
</div>
的Servlet
String rtempfile = File.createTempFile("temp", "1").getParent();
MultipartRequest multi = new MultipartRequest(request, rtempfile, 15*1024*1024);
Enumeration files = multi.getFileNames();
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List<FileItem> items = upload.parseRequest(request);
Iterator<FileItem> iter = items.iterator();
while(iter.hasNext()) {
FileItem item = iter.next();
if(item.isFormField()) {
String name = item.getFieldName();
String value = item.getString();
if(name.equals("orderid2"))
order.setOrderID(Integer.parseInt(value));
else if(name.equals("remarks"))
order.setRemarks(value);
}
}
orderDAO.submitResult(order, multi, files);
答案 0 :(得分:0)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="author" content="">
<!--[if IE]><meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'><![endif]-->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<!-- TITLE -->
<title>Home | The Ajax Project</title>
<!-- Favicons -->
<!-- STYLES -->
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/style.css">
</head>
<body>
<div class="nav-bar">
<div class="nav-container">
<div class="nav-toggle">
<a href="">
<span class="bar-1"></span>
<span class="bar-2"></span>
<span class="bar-3"></span>
</a>
</div>
<ul class="nav-menu">
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="contact.html">contact</a></li>
</ul>
</div>
</div>
<div id="content">
<section class="page-sect" data-bg="assets/images/slides/slide1.jpg">
<div class="home-section">
<div class="container-fluid">
<div class="row">
<div class="col-md-5 col-md-offset-1">
<h1 class="main-heading">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Architecto in vero a. </h1>
</div>
</div>
</div>
</div>
</section>
<section class="fullwidth">
<div class="container">
<div class="row">
<div class="col-md-6">
<h5>This is the first Page</h5>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rem nihil perspiciatis saepe harum eos quas aut. Quod blanditiis voluptatibus culpa beatae accusantium, consectetur nihil sequi ipsum, deserunt sapiente ratione repellat, amet enim? </p>
</div>
<div class="col-md-6">
<h5>This is the first Page</h5>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rem nihil perspiciatis saepe harum eos quas aut. Quod blanditiis voluptatibus culpa beatae accusantium, consectetur nihil sequi ipsum, deserunt sapiente ratione repellat, amet enim? </p>
</div>
</div>
</div>
</section>
</div>
<script type="text/javascript" src="assets/js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="assets/js/jquery-ui.min.js"></script>
<script type="text/javascript" src="assets/js/bootstrap.min.js"></script>
<script id="runscript" type="text/javascript" src="assets/js/custom.js"></script>
<script id="runscript" type="text/javascript" src="assets/js/test.js"></script>
<script type="text/javascript" src="assets/js/ajax.js"></script>
</body>
</html>