Как загрузить файл в форме jsp без действия кнопки submit
I have a jsp page here, the upload will show up based on one of the dropdown value. till there its working fine. I have used submit action for upload here. but also tried Ajax call etc...nothing working :( ideal goal is to upload file without submit action. Kindly assist how we can achieve this. it would be great help.Thanks
Что я уже пробовал:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <html> <style type="text/css"> body { background-image: url('https://cdn.crunchify.com/wp-content/uploads/2013/03/Crunchify.bg_.300.png'); } </style> <head> <meta charset="UTF-8"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>First JSP Servlet Example</title> </head> <body> <div align="center" style="margin-top: 50px;"> <form action="FirstwebServlet"> <br> Please select the option : <select required="required" name="sel" id="selType"> <option value="None">Choose from the list</option> <option value="MyReport">MyReport</option> <option value="Myview">Myview</option> <option value="mycustom">mycustom</option> </select> <br> <form id="upload-form" class="upload-box" action="/Upload" method="post" enctype="multipart/form-data"> <div id="otherType" style="display: none;"> <input type="file" id="file" name="file1" /> <span id="upload-error" class="error">${uploadError}</span> <input type="submit" id="upload-button" value="upload" /> </div> </form> <input type="submit" value="submit"> </form> </div> <script src="jquery.js"></script> <script src="jquery.form.js"></script> <script> $(function() { $('#upload-form').ajaxForm({ success: function(msg) { alert("File has been uploaded successfully"); }, error: function(msg) { $("#upload-error").text("Couldn't upload file"); } }); }); </script> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script> <script> $('#selType').change(function(){ selection = $(this).val(); switch(selection) { case 'Mycustomtemplate': $('#otherType').show(); break; default: $('#otherType').hide(); break; } }); </script> </body> </html>
Member 12974741
Извини, что не получаю. Могу я узнать, что вы рекомендуете? я пробовал в google fu... пробовал немногие не работали с jsp. вот почему поднял вопрос здесь, думая, что я могу получить некоторые идеи. Спасибо