好久沒有更新部落格了,寫了個jsp 上傳組件給大家看看
1.下載下來,建立個j2ee工程,把qingcai-upload.jar放到lib下,然後upload.tld放到WEB-INF下。
2.在web.xml
例如:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd"
id="WebApp_ID" version="2.4">
<display-name>aa</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<taglib>
<taglib-uri>/upload</taglib-uri>
<taglib-location>/WEB-INF/upload.tld</taglib-location>
</taglib>
<servlet>
<servlet-name>UploadServlet</servlet-name>
<servlet-class>com.qingcai.upload.servlet.UploadServlet</servlet-class>
<init-param>
<param-name>savePath</param-name>
<param-value>C:\\upload\\</param-value>
</init-param>
<init-param>
<param-name>extension</param-name>
<param-value>gif,rar</param-value>
</init-param>
<init-param>
<param-name>maxFileSize</param-name>
<param-value>20</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>UploadServlet</servlet-name>
<url-pattern>/fileupload</url-pattern>
</servlet-mapping>
</web-app>
3.建立個jsp
如
<%@ page language="java" contentType="text/html; charset=GBK"
pageEncoding="GBK"%>
<%@ taglib uri="/upload" prefix="qingcaiUpload"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>Insert title here</title>
</head>
<body>
<qingcaiUpload:upload/>
</body>
</html>
這樣就可以調用了
這才是最基礎的上傳,我近幾天會把功能做的更完善點,然後會把代碼發出來,一起去研究,一起探討。
本文配套源碼