最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
怎么在Java項(xiàng)目中利用Struts將圖片上傳到指定文件夾-創(chuàng)新互聯(lián)

怎么在Java項(xiàng)目中利用Struts將圖片上傳到指定文件夾?很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。

成都創(chuàng)新互聯(lián)專(zhuān)注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都做網(wǎng)站、成都網(wǎng)站設(shè)計(jì)、綏德網(wǎng)絡(luò)推廣、重慶小程序開(kāi)發(fā)公司、綏德網(wǎng)絡(luò)營(yíng)銷(xiāo)、綏德企業(yè)策劃、綏德品牌公關(guān)、搜索引擎seo、人物專(zhuān)訪、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠(chéng)為您服務(wù),您的肯定,是我們大的嘉獎(jiǎng);成都創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供綏德建站搭建服務(wù),24小時(shí)服務(wù)熱線:13518219792,官方網(wǎng)址:www.cdcxhl.com

JSP上傳頁(yè)面

上傳一定要為form加上enctype="multipart/form-data",表示提交的數(shù)據(jù)時(shí)二進(jìn)制的

并且必須是method="post"

<%@ page language="java" contentType="text/html; charset=utf-8"
  pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>






 
 



struts.xml配置(maven項(xiàng)目放在resources)

 
 
   
      設(shè)置文件上傳大值
     
       
        /fail.jsp 
        /success.jsp
       
     
  

TestStruts.java控制類(lèi)

一定要提供三個(gè)屬性

File img;
String imgFileName;
String imgContentType;

然后為這3個(gè)屬性提供getter setter方法

package com.controller;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class TestStruts extends ActionSupport{
  private File img;
  private String imgFileName;
  private String imgContentType;
  public File getImg(){
    return img;
  }
  public String getimgFileName(){
    return imgFileName;
  }
  public String getImgContentType(){
    return imgContentType;
  }
  public void setImg(File img){
    this.img = img;
  }
  public void setImgFileName(String imgFileName){
    this.imgFileName = imgFileName;
  }
  public void setImgFileContentType(String imgContentType){
    this.imgContentType = imgContentType;
  }
  @SuppressWarnings("unchecked")
  public String logintest() throws IOException{
    Map p = ActionContext.getContext().getSession();
    p.put("imgFileName", imgFileName);
    File f = new File("D://imagebystruts");
    if (!f.exists()) { 
      f.mkdir(); 
    }     
    FileUtils.copyFile(img, new File(f, imgFileName));
    return "success";
  }
}

Tomcat中server.xml文件配置虛擬路徑


success.jsp顯示圖片

<%@ page language="java" contentType="text/html; charset=utf-8"
  pageEncoding="utf-8"%>

<%@ taglib prefix="s" uri="/struts-tags" %> 



success


成功

        

看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對(duì)創(chuàng)新互聯(lián)的支持。


網(wǎng)頁(yè)名稱:怎么在Java項(xiàng)目中利用Struts將圖片上傳到指定文件夾-創(chuàng)新互聯(lián)
當(dāng)前URL:http://fisionsoft.com.cn/article/deisec.html