創(chuàng)新互聯(lián)www.cdcxhl.cn八線動態(tài)BGP香港云服務(wù)器提供商,新人活動買多久送多久,劃算不套路!
利用javaweb如何實(shí)現(xiàn)一個文件上傳功能?針對這個問題,這篇文章詳細(xì)介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
具體內(nèi)容如下
文件上傳示例
注意:jsp頁面編碼為"UTF-8"
文件上傳的必要條件
1.form表單,必須為POST方式提交
2.enctype="multipart/form-data"
3.必須有<input type="file" />
前端jsp頁面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>" rel="external nofollow" > <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css" rel="external nofollow" > --> </head> <script type="text/javascript"> function addFile(){ var div1=document.getElementById("div1"); div1.innerHTML+="<div><input type='file' /><input type='button' value='刪除' onclick='deleteFile(this)' /> <br/></div>"; } function deleteFile(div){ //他的爺爺刪除他的爸爸 div.parentNode.parentNode.removeChild(div.parentNode); } </script> <body> <form action="${pageContext.request.contextPath }/servlet/upLoadServlet" method="post" enctype="multipart/form-data"> 文件的描述:<input type="text" name ="description" /><br/> <div id="div1"> <div> <input type="file" name ="file" /><input type="button" value="添加" onclick="addFile()" /><br/> </div> </div> <input type="submit" /> </form> </body> </html>
新聞名稱:利用javaweb如何實(shí)現(xiàn)一個文件上傳功能-創(chuàng)新互聯(lián)
轉(zhuǎn)載來于:http://www.chinadenli.net/article18/gsidp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、外貿(mào)網(wǎng)站建設(shè)、響應(yīng)式網(wǎng)站、ChatGPT、全網(wǎng)營銷推廣、域名注冊
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容