차차차차차차
10
2019-08-06 18:07:48
0
170

자바 이클립스 업로드 오류 (Posted content type isn't multipart/form-data)






HTTP Status 500 – Internal Server Error


Type Exception Report

Message An exception occurred processing [/uploadAction.jsp] at line [21]

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

java.io.IOException: An exception occurred processing [/uploadAction.jsp] at line [21]

18: 		String encoding = "UTF-8";
19: 		
20: 		MultipartRequest multipartRequest
21: 		= new MultipartRequest(request, directory, maxSize, encoding,
22: 				new DefaultFileRenamePolicy());
23: 		
24: 		String fileName = multipartRequest.getOriginalFileName("file");


Stacktrace:
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:504)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

Root Cause

java.io.IOException: Posted content type isn't multipart/form-data
	com.oreilly.servlet.multipart.MultipartParser.<init>(MultipartParser.java:168)
	com.oreilly.servlet.MultipartRequest.<init>(MultipartRequest.java:223)
	org.apache.jsp.uploadAction_jsp._jspService(uploadAction_jsp.java:137)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

Note The full stack trace of the root cause is available in the server logs.


write.jsp


<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.io.PrintWriter" %> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width", initial-scale="1"> <link rel="stylesheet" href="css/bootstrap.css"> <link rel="stylesheet" href="css/custom.css"> <title>3D MAKERS</title> </head> <body> <% String userID = null; if (session.getAttribute("userID") != null) { userID = (String) session.getAttribute("userID"); } %> <nav class="navbar navbar-default"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="main.jsp">3D MAKERS</a> </div> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <ul class="nav navbar-nav"> <li><a href="main.jsp">메인</a></li> <li class="active"><a href="3DMAKERS.jsp">게시판</a></li> </ul> <% if(userID == null) { %> <ul class="nav navbar-nav navbar-right"> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">접속하기<span class="caret"></span></a> <ul class="dropdown-menu"> <li><a href="login.jsp">로그인</a></li> <li><a href="join.jsp">회원가입</a></li> </ul> </li> </ul> <% } else { %> <ul class="nav navbar-nav navbar-right"> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">회원관리<span class="caret"></span></a> <ul class="dropdown-menu"> <li><a href="logoutAction.jsp">로그아웃</a></li> </ul> </li> </ul> <% } %> </div> </nav> <div class="container"> <div class="row"> <form action="uploadAction.jsp" method="post" enctype="multipart/form-data" method="post" action="writeAction.jsp"> 파일:<input type="file" name="file"><br> <table class="table table-striped" style="text-align; center; border: 1px solid #dddddd"> <thead> <tr> <th colspan="2" style="background-color: #eeeeee; text-align: center;">게시판 글쓰기 양식</th> </tr> </thead> <tbody> <tr> <td><input type="text" class="form-control" placeholder="글 제목" name="bbsTitle" maxlength="50"></td> </tr> <tr> <td><textarea class="form-control" placeholder="글 내용" name="bbsContent" maxlength="2048" style="height: 350px;"></textarea></td> </tr> </tbody> </table> <input type="submit" class="btn btn-primary pull-right" value="글쓰기"> </form> </div> </div> <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> </body> </html>

writeAction.jsp


<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="bbs.BbsDAO" %> <%@ page import="java.io.PrintWriter" %> <% request.setCharacterEncoding("UTF-8"); %> <jsp:useBean id="bbs" class="bbs.Bbs" scope="page" /> <jsp:setProperty name="bbs" property="bbsTitle" /> <jsp:setProperty name="bbs" property="bbsContent" /> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=UTF-8"> <title>3D MAKERS</title> </head> <body> <% String userID = null; if (session.getAttribute("userID") != null) { userID = (String) session.getAttribute("userID"); } if(userID == null) { PrintWriter script = response.getWriter(); script.println("<script>"); script.println("alert('로그인을 하세요.')"); script.println("location.href = 'login.jsp'"); script.println("</script>"); } else { if (bbs.getBbsTitle() == null || bbs.getBbsContent() == null) { PrintWriter script = response.getWriter(); script.println("<script>"); script.println("alert('입력이 안 된 사항이 있습니다.')"); script.println("history.back()"); script.println("</script>"); } else { BbsDAO bbsDAO = new BbsDAO(); int result = bbsDAO.write(bbs.getBbsTitle(), userID, bbs.getBbsContent()); if (result == -1) { PrintWriter script = response.getWriter(); script.println("<script>"); script.println("alert('글쓰기에 실패했습니다.')"); script.println("history.back()"); script.println("</script>"); } else { PrintWriter script = response.getWriter(); script.println("<script>"); script.println("location.href = 'uploadAction.jsp'"); script.println("</script>"); } } } %> </body> </html>





uploadAction.jsp

<%@ page import="file.FileDAO" %> <%@ page import="java.io.File" %> <%@ page import="com.oreilly.servlet.multipart.DefaultFileRenamePolicy" %> <%@ page import="com.oreilly.servlet.MultipartRequest" %> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" href="css/custom.css"> <title>3D MAKERS</title> </head> <body> <% String directory= application.getRealPath("/upload/"); int maxSize = 1024 * 1024 * 100; String encoding = "UTF-8"; MultipartRequest multipartRequest = new MultipartRequest(request, directory, maxSize, encoding, new DefaultFileRenamePolicy()); String fileName = multipartRequest.getOriginalFileName("file"); String fileRealName = multipartRequest.getFilesystemName("file"); new FileDAO().upload(fileName, fileRealName); out.write("파일명: "+fileName+ "<br>"); out.write("실제 파일명: "+fileRealName+ "<br>"); %> </body> </html>

0
0
  • 댓글 0

  • 로그인을 하시면 댓글을 등록할 수 있습니다.