當前位置:首頁 » 網頁前端 » 文件上傳資料庫javaweb
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

文件上傳資料庫javaweb

發布時間: 2022-12-07 06:43:31

❶ java web怎麼上傳圖片到指定的項目文件夾,並獲取該路徑,將路徑存儲資料庫,用相對路徑哦

當前項目的路經,通過request.getSession().getServletContext().getRealPath("/")獲取到的

❷ java web開發如何將本幾上的excel文件中的數據導入到mysql資料庫中,是web開發不是java se

首先需要上傳文件的功能,把文件上傳到伺服器指定的位置後,用jxl.jar包讀取excel文件中的內容,把每一行的內容作為一條記錄保存到資料庫中

❸ java web項目 上傳資料代碼 為什麼上傳成功卻找不到文件

上傳成功的話,注意要在tomcat/jboss下,找文件。

為什麼呢?
因你你是發布在tomcat/jboss下,故文件布置在伺服器下,不要去myeclipse或eclipse下找。

通過「 Could not remove uploaded file 'C:\tmp\upload_76202ce9_145029000b6__8000_00000035.tmp'.」;可知,你上傳未成功,且與資料庫的連接也未成功。

❹ java web項目表單信息是如何傳值傳到資料庫的

除了AJAX方案以外,一般都是通過get/post請求把數據發送到伺服器端,然後伺服器通過WEB層控制器接收到請求,處理下數據,然後轉到service層處理業務,然後到DAO數據持久層進行存儲數據.大概就是這樣.

❺ java web怎麼實現文件上傳到伺服器

/**
* 上傳到本地
* @param uploadFile
* @param request
* @return
*/
@RequestMapping("/upload")
@ResponseBody
public Map<String, Object> uploadApkFile(@RequestParam("uploadUpdateHistoryName") MultipartFile uploadFile,
HttpServletRequest request) {
Map<String, Object> map = new HashMap<>();
// 上傳文件校驗,包括上傳文件是否為空、文件名稱是否為空、文件格式是否為APK。
if (uploadFile == null) {
map.put("error", 1);
map.put("msg", "上傳文件不能為空");
return map;
}
String originalFilename = uploadFile.getOriginalFilename();
if (StringUtils.isEmpty(originalFilename)) {
map.put("error", 1);
map.put("msg", "上傳文件名稱不能為空");
return map;
}
String extName = originalFilename.substring(originalFilename.lastIndexOf(".") + 1);
if (extName.toUpperCase().indexOf("APK") < 0) {
map.put("error", 1);
map.put("msg", "上傳文件格式必須為APK");
return map;
}

String path = request.getSession().getServletContext().getRealPath("upload");
String fileName = uploadFile.getOriginalFilename();
File targetFile = new File(path, fileName);
if (!targetFile.exists()) {
targetFile.mkdirs();
}
// 保存
String downLoadUrl = null;
try {
uploadFile.transferTo(targetFile);
downLoadUrl = request.getContextPath() + "/upload/" + fileName;
map.put("error", 0);
map.put("downLoadUrl", downLoadUrl);
map.put("msg", "上傳文件成功");
return map;
} catch (Exception e) {
e.printStackTrace();
map.put("error", 1);
map.put("msg", "上傳文件失敗");
return map;
}
}

//上傳文件
$('#btnUpload').bind('click',function(){
// var formdata= $('#uploadForm').serializeJSON();
var formdata = new FormData($( "#uploadForm" )[0]);
$.ajax({
url:"upload.do",
data:formdata,
async: false,
cache: false,
processData:false,
contentType:false,
// dataType:'json',
type:'post',
success:function(value){
if(value.error==0){
$('#downLoadUrlId').val(value.downLoadUrl);
$.messager.alert('提示',value.msg);
$('#uploadWindow').window('close');
}else{
$.messager.alert('提示',value.msg);
}
}
});
});

<div id="uploadWindow" class="easyui-window" title="apk上傳"
style="width: 230px;height: 100px" data-options="closed:true">
<form id="uploadForm" enctype="multipart/form-data">
<td><input type ="file" style="width:200px;" name = "uploadUpdateHistoryName"></td>
</form>
<button id="btnUpload" type="button">上傳Apk</button>
</div>

java js html

❻ java web 怎麼導入excel文件

1.要正確的將Web客戶端的Excel文件導入到伺服器的資料庫中,需要將客戶端的Excel文件上傳到伺服器上。可以使用FileUpload控制項完成。2.Excel文件上傳到伺服器指定的目錄中,這里假設是該站點的upfiles目錄中。3.使用SQL語句從upfiles目錄中的上傳Excel文件中讀取數據顯示或寫入資料庫。

❼ java web開發,上傳圖片並讀取

java web開發中,使用文件操作類來上傳圖片並讀取,如下代碼:

*@desc:圖片處理工具
*@author:bingye
*@createTime:2015-3-17下午04:25:32
*@version:v1.0
*/
publicclassImageUtil{

/**
*將圖片寫到客戶端
*@author:bingye
*@createTime:2015-3-17下午04:36:04
*@history:
*@paramimage
*@paramresponsevoid
*/
publicstaticvoidwriteImage(byte[]image,HttpServletResponseresponse){
if(image==null){
return;
}
byte[]buffer=newbyte[1024];
InputStreamis=null;
OutputStreamos=null;
try{
is=newByteArrayInputStream(image);
os=response.getOutputStream();
while(is.read(buffer)!=-1){
os.write(buffer);
os.flush();
}
}catch(IOExceptione){
e.printStackTrace();
}finally{
try{
if(is!=null){is.close();}
if(os!=null){os.close();}
}catch(IOExceptione){
e.printStackTrace();
}
}
}

/**
*獲取指定路勁圖片
*@author:bingye
*@createTime:2015-3-21上午10:50:44
*@paramfilePath
*@paramresponsevoid
*/
publicstaticvoidwriteImage(StringfilePath,HttpServletResponseresponse){
FileimageFile=newFile(filePath);
if(imageFile!=null&&imageFile.exists()){
byte[]buffer=newbyte[1024];
InputStreamis=null;
OutputStreamos=null;
try{
is=newFileInputStream(imageFile);
os=response.getOutputStream();
while(is.read(buffer)!=-1){
os.write(buffer);
os.flush();
}
}catch(FileNotFoundExceptione){
e.printStackTrace();
}catch(IOExceptione){
e.printStackTrace();
}finally{
try{
if(is!=null){is.close();}
if(os!=null){os.close();}
}catch(IOExceptione){
e.printStackTrace();
}
}
}
}

/**
*圖片上傳到文件夾
*@author:bingye
*@createTime:2015-3-20下午08:07:25
*@paramfile
*@paramsavePath
*@returnboolean
*/
(CommonsMultipartFilefile,StringsavePath){
if(file!=null&&!file.isEmpty()){
//獲取文件名稱
StringfileName=file.getOriginalFilename();
//獲取後綴名
StringsuffixName=fileName.substring(fileName.indexOf(".")+1);
//新名稱
StringnewFileName=System.currentTimeMillis()+"."+suffixName;
//新文件路勁
StringfilePath=savePath+newFileName;
//獲取存儲文件路徑
FilefileDir=newFile(savePath);
if(!fileDir.exists()){
//如果文件夾沒有:新建
fileDir.mkdirs();
}
FileOutputStreamfos=null;
try{
fos=newFileOutputStream(filePath);
fos.write(file.getBytes());
fos.flush();
returnResultUtil.success("UPLOAD_SUCCESS",URLEncoder.encode(newFileName,"utf-8"));
}catch(Exceptione){
e.printStackTrace();
returnResultUtil.fail("UPLOAD_ERROR");
}finally{
try{
if(fos!=null){
fos.close();
}
}catch(IOExceptione){
e.printStackTrace();
returnResultUtil.fail("UPLOAD_ERROR");
}
}
}
returnResultUtil.fail("UPLOAD_ERROR");
}}

❽ java web 如何實現將excel表導入到資料庫

正解,poi
讀取excel
文件,然後一行行的,保存到資料庫。

❾ java web 本地端上傳文件到伺服器端

Web文件上傳採用POST的方式,與POST提交表單不同的是,上傳文件需要設置FORM的enctype屬性為multipart/form-data.由於上傳的文件會比較大,因此需要設置該參數指定瀏覽器使用二進制上傳。如果不設置,enctype屬性默認為application/x-www-form-urlencoded,使用瀏覽器將使用ASCII向伺服器發送數據,導致發送文件失敗。
上傳文件要使用文件域(<input type='file'/>,並把FORM的Enctype設置為multipart/form-data.