enctype="multipart/form-data"ã«ããã¨reqeust.getParameter()ãnullãè¿ãåé¡ã®å¯¾ç
ã¨ããããslim3ã ã¨getParameter()ã¯åãããã©ãgetParameterValues()ãnullã«ãªã£ã¦å°ã£ãã
JSPã¯ãããªãã
<form id="form" action="/hoge" enctype="multipart/form-data" method="post" > <input type="text" name="name" /> <input type="file" name="image" accept="image/*" /> <c:forEach var="o" items="${checks}"> <span><input id="checks_${o.id}" type="checkbox" name="checks" value="${o.id}" ${o.checked} > <label>${o.name}</label></span> </c:forEach> <input type="submit" value="send" /> </form>
ãããã¨commons-fileupload 使ãã°ã§ããã¨ããã£ããã©ãslim3ã ã¨ç¸æ§ã®ãããªã®ãã§ããªãã£ãã
ajaxã§2åã«åãã¦postããããã«ããã
JSPã®ãã©ã¼ã ããenctypeãåé¤ãã¨ãã
Servletå´ã§åºå¥ã§ããããã«hiddenã追å ãã¨ãã
<form id="form" action="/hoge" method="post" > <input type="text" name="name" /> <input type="file" name="image" accept="image/*" /> <c:forEach var="o" items="${checks}"> <span><input id="checks_${o.id}" type="checkbox" name="checks" value="${o.id}" ${o.checked} > <label>${o.name}</label></span> </c:forEach> <input type="hidden" name="upload" value="no" /> <input type="button" value="send" onclick="send()" /> </form>
JavaScriptããããªãã
1åç®ã®postã§ã¯fileãdisabledã«ãã¦ç¡è¦ãããã
2åãã®poståã«enctypeã追å ããã
ããªãã¦ãããããã ãã©ãfile以å¤ã®inputãdisabledã«ãã¨ãã
hiddenã®å¤ãã念ã®ããã«ç©ºæååã«ãã¨ãã
function send() { $('input[type=file]').prop('disabled', true); $.ajax({ type: 'post', data: $('#form').serialize(), success: function (data) { upload(); } }); } function upload() { $('input').prop('disabled', true); $('input[type=file]').prop('disabled', false); $('input[type=hidden]').val(''); $('#form').prop('enctype', 'multipart/form-data'); $('#form').submit(); }
Servletå´ã¯ getParameter("upload") ã®æç¡ã§å¦çãåãåããã
String s = request.getParameter("upload"); if (s == null || s.isEmpty()) { // ãã¡ã¤ã«ãåä¿¡ } else if (s.equals("no")) { // å ¥åãã©ã¼ã ã®å¤ãåå¾ }