이 글은 기계 번역의 미러 문서이며, 원본 기사로 바로 이동하려면 여기를 클릭해 주세요.

보기: 12948|회답: 0

[자바EE] struts2file 업로드

[링크 복사]
게시됨 2014. 12. 24. 오전 2:12:11 | | |
[mw_shl_code=자바, 참]
  <body><%--
  ORM 폼은 바이너리 형식으로 쿼리되며, enctype="multipart/form-data"를 설정해야 합니다
    --%><form action="${pageContext.request.contextPath}/de/ServletActionupload" enctype="multipart/form-data" method="post"/>
            file<input type="file" name="image"/>
            <input type="submit" value="upload"/>
    </form>
  </body>

        <action name="ServletAction*" class="action.ServletAction" method="{1}">
                <결과 이름="message">/index.jsp</result>
                <결과 이름="uploadmsg">/uploadmsg.jsp</result>
                </action>

...
개인 파일 이미지;
        개인 문자열 imageFileName; 필드 이름 뒤에는 파일이름이 뒤따릅니다
       
       
       
        public String getImageFileName() {
                imageFileName을 반환;
        }

        public void setImageFileName(String imageFileName) {
                this.imageFileName = imageFileName;
        }

        public File getImage() {
                이미지 반환;
        }

        public void setImage(File image) {
                this.image = image;
        }


/**
         * 파일 업로드
         * @return
         * @throws IOException
         */
        public String upload(){
               
                        시도해 {
                                String realpath = ServletActionContext.getServletContext().getRealPath("/images");
System.out.println(realpath);
만약 (image!=null) {
                                파일 savefile = new File(new File(realpath), imageFileName);
                                만약 (!savefile.getParentFile().exists()) {
                                        savefile.getParentFile().mkdir();
                                }
                                FileUtils.copyFile(image,savefile);
                                ActionContext.getContext().put("msg", "업로드 성공!");
                               
}else {
ActionContext.getContext().put("msg", "파일 선택하세요");
}
                        } catch (IOException e) {
                                TODO 자동 생성 캐치 블록
                                e.printStackTrace();
                                ActionContext.getContext().put("msg", "업로드 실패!");
                        }
                "UploadMSG"로 반환;
        }


[/mw_shl_code]




이전의:이 포럼이 너무 텅 비어 있는 것 같아요, 그냥 사진 올리면 아무도 안 읽어요. 하
다음:Struts2 맞춤 시간 변환기
면책 조항:
Code Farmer Network에서 발행하는 모든 소프트웨어, 프로그래밍 자료 또는 기사는 학습 및 연구 목적으로만 사용됩니다; 위 내용은 상업적 또는 불법적인 목적으로 사용되지 않으며, 그렇지 않으면 모든 책임이 사용자에게 부담됩니다. 이 사이트의 정보는 인터넷에서 가져온 것이며, 저작권 분쟁은 이 사이트와는 관련이 없습니다. 위 내용은 다운로드 후 24시간 이내에 컴퓨터에서 완전히 삭제해야 합니다. 프로그램이 마음에 드신다면, 진짜 소프트웨어를 지원하고, 등록을 구매하며, 더 나은 진짜 서비스를 받아주세요. 침해가 있을 경우 이메일로 연락해 주시기 바랍니다.

Mail To:help@itsvse.com