I am learning JSP and I can't find an answer to the following question:
I want to upload the image file in one page, pass it to another and show it there like (based on this question):
first.jsp
<form method="post" onsubmit="save()" action="second.jsp" enctype="multipart/form-data">
<input type="file" name="openFile" onchange="reloadPreview()">
<canvas name="preview"></canvas>
<input type="submit" value="Save"/>
</form>
<script>
function reloadPreview(){
var preview = document.getElementsByName("preview")[0];
var file = document.getElementsByName("openFile")[0].files[0];
var reader = new FileReader();
var picture = new Image;
reader.onloadend = function () {
picture.src = reader.result;
preview.width = picture.width;
preview.height = picture.height;
var context = preview.getContext("2d");
context.drawImage(picture, 0, 0);
dataUrl = preview.toDataURL();
};
if (file) {
reader.readAsDataURL(file);
}
}
function save() {
window.location = "second.jsp?imgUrl="+dataUrl;
document.getElementById("form").submit();
}
var dataUrl;
</script>
1) What should I do to access canvas content from second.jsp
?
2) Can I access openFile
file without uploading it to canvas
(for example if file is not an image)?
Source:
<%session.setAttribute("Down1","download.png");%>
<td>Image: </td>
<td><img src="download.png" width="516" height="516" alt="Down" name="Down1"/></td>
Destination:
<td><img src="download.png" width="516" height="516" alt="Down" name="Down1"/></td>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.