1.JSP ä¸ä¼ ä¸è½½ä»£ç
2.C# 如何将上传到指定服务器的源码目录下?求源码
3.问个关于上传组建的问题!
JSP ä¸ä¼ ä¸è½½ä»£ç
æç»ä½ æï¼
1.é¦å ä¸è¿ä¸¤ä¸ªå commons-fileupload-1.2.1.jarï¼commons-io-1.3.2.jar
2.ç¼ååå°é¡µé¢
<%@ page language="java" pageEncoding="gbk"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4. Transitional//EN">
<html>
<body>
<form action="<%=request.getContextPath()%>/UploadServlet" method="post" enctype="multipart/form-data">
username:<input type="text" name="username"><br>
password:<input type="password" name="password"><br>
file:<input type="file" name="file"><br>
<input type="submit" value="submit"><br>
</form>
</body>
</html>
3.ç¼åservlet
package cn.jci.upload.servlet;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet..jci.upload.servlet.UploadServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UploadServlet</servlet-name>
<url-pattern>/UploadServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
5.åå¸
okäº
è¿æ¯æåå§çä¸ä¼ æ件çåæ³ï¼ç°å¨struts2ä¸ä¼ çè¯ï¼å°±è¦è½»æ¾å¥½å¤
C# 如何将上传到指定服务器的目录下?求源码
用FileUpload控件 做个死循环一直赋值上传,这样行么?
下面是源码aspx无法查看源码fileupload上传代码
if (UploadImg.PostedFile.FileName != "")
{
string ImgPath = UploadImg.PostedFile.FileName;
ImgName = ImgPath.Substring(ImgPath.LastIndexOf("\\") + 1);
string ImgExtend = ImgPath.Substring(ImgPath.LastIndexOf(".") + 1);
if (!(ImgExtend == "bmp" || ImgExtend == "jpg" || ImgExtend == "gif"))
{
Label1.Visible = true;
ImgName = "noImage.gif";
return;
}
Photo = Server.MapPath("~/Images/") + ImgName;
UploadImg.PostedFile.SaveAs(Photo);
}
问个关于上传组建的问题!
//这是我之前做项目的源代码,应该对你有帮助
/**Create a factory for disk-based file items*/
DiskFileItemFactory factory = new DiskFileItemFactory();
/**设置最大的源码javascript轮播图源码内存大小*/
factory.setSizeThreshold();
/**创建一个新的文件上传操作*/
ServletFileUpload upload = new ServletFileUpload(factory);
/**设置能上传的最大文件的大小*/
upload.setSizeMax(*);
/**Parse the request*/
List fileItems = upload.parseRequest(request);
//开始读取上传信息
Iterator iter = fileItems.iterator();
// 依次处理每个上传的文件
while(iter.hasNext()) {
FileItem item = (FileItem) iter.next();
// 忽略其他不是文件域的所有表单信息
if (!item.isFormField()) {
String name = item.getName();
String endName = name.substring(name.lastIndexOf(".") + 1);
try{
item.write(new File(request.getRealPath("\\"+sUploadDir+FileName+"."+ endName)));
}catch(Exception e){
e.printStackTrace();
}