package com
public class Constant {
private Constant() {
}
public static Integer pictureSize =
public static String pictureDirectory =
}
package com
import java
import java
import java
import java
import java
import java
import java
import java
import java
import javax
import javax
import org
import org
import org
public class PictureUpLoad {
private PictureUpLoad() {
}
private static boolean isValidFile(String fileName) {
String[] validFiles = {
boolean ret = false;
for (int i =
if (fileName
ret = true;
break;
}
}
return ret;
}
private static String rebuildFileName(String fileName) {
java
java
return sdf
}
private static String lianjieFileName(String fileName){
return
}
private static boolean isDirectoryExists(String path){
java
if(!file
return file
}else
return true;
}
private static String[] getFileName(String filesName){
Pattern x=pile(
String[] fileName = filesName
Matcher t = x
System
return fileName;
}
public static String[] fileUpLoad(ActionForm form
HttpServletRequest request
throws Exception {
String path =
String fileName =
MultipartRequestHandler handle = form
Hashtable hashTable = handle
Collection cln = hashTable
Iterator iterator = erator();
while (iterator
FormFile file = (FormFile) iterator
path = request
if(isDirectoryExists(path)==false) return null;
if (file
return null;
if (file
return null;
if (!isValidFile(file
return null;
try {
InputStream in = file
OutputStream out = new FileOutputStream(path
+ rebuildFileName(file
int bytesRead =
byte[] buffer = new byte[
while ((bytesRead = in
out
}
out
in
} catch (Exception e) {
e
}
fileName=fileName+lianjieFileName(rebuildFileName(file
}
return getFileName(fileName);
}
}
package com
import java
import java
import java
import java
import java
import java
import javax
import javax
import org
import org
import org
import org
import org
import org
import com
/**
* MyEclipse Struts Creation date:
*
* XDoclet definition:
*
* @struts
* @struts
*/
public class UploadAction extends Action {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping
HttpServletRequest request
// TODO Auto
UploadForm updForm = (UploadForm)form;
try {
String[] fileNames = PictureUpLoad
request
System
for(String file:fileNames){
System
}
} catch (Exception e) {
// TODO Auto
e
}
return mapping
}
}
package com
import javax
import org
import org
import org
/**
* MyEclipse Struts
* Creation date:
*
* XDoclet definition:
* @struts
*/
public class UploadForm extends ActionForm {
/*
* Generated fields
*/
/** name property */
private String name;
/*
* Generated Methods
*/
/**
* Method validate
* @param mapping
* @param request
* @return ActionErrors
*/
public ActionErrors validate(ActionMapping mapping
HttpServletRequest request) {
// TODO Auto
return null;
}
/**
* Method reset
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping
// TODO Auto
}
/**
* Returns the name
* @return String
*/
public String getName() {
return name;
}
/**
* Set the name
* @param name The name to set
*/
public void setName(String name) {
this
}
}
index
<%@ page language=
<!DOCTYPE HTML PUBLIC
<html>
<head>
<title>struts upload by zhangc</title>
</head>
<body>
<a >create</a><br>
</body>
</html>
new
<%@ page language=
<%@ taglib uri=
<%@ taglib uri=
<html>
<head>
<title>struts upload by zhangc</title>
<script language=
var rnum =
function addRow()
{
var oT = document
var newTR = oT
newTR
var newTD
var newTD
newTD
newTD
newTD
+ rnum
+
rnum++;
}
function deleteRow(line)
{
oTable
}
</script>
</head>
<body>
<form name=
<table id=
<tr>
<td>name:</td>
<td><input name=
</tr>
<tr>
<td>上傳圖片:</td>
<td><input type=file name=
</tr>
<tr>
<td><input name=
</tr>
</table>
</form>
</body>
</html>
next
<%@ page language=
<%@ taglib prefix=
<%
String path = request
String basePath = request
+ request
+ path +
%>
<!DOCTYPE HTML PUBLIC
<html>
<head>
<base <%=basePath%>
<title>My JSP
<meta http
<meta http
<meta http
<meta http
<meta http
<!
<link rel=
</head>
<body>
<c:forEach var=
<img alt=
</c:forEach>
</body>
</html>
<?xml version=
<!DOCTYPE struts
<struts
<data
<form
<form
</form
<global
<global
<action
<action
input=
path=
type=
scope=
<forward
name=
path=
</action>
</action
<message
</struts
From:http://tw.wingwit.com/Article/program/Java/ky/201311/28037.html