从数据库中检索信息时,如何在“选择照片”框中放置存储在数据库中的照片的url?

时间:2019-04-27 16:10:55

标签: html jsp

我制作了一个弹出表单,用于从数据库中检索与给定ID匹配的信息。我想将照片及其网址保存在框中。

我已经尝试过这样做:

document.getElementById('id of the input file box').value="the source of the photo"; 

,但是它不起作用。

ResultSet rst=stmt.executeQuery("select * from Teacher_Registration_Form where Te_UID='"+uid+"' ");
````
<form action="page.jsp" method="post" enctype="multipart/form-data">
<div class="box">
<a class="button" href="#popup1" onClick="myFunction()">Edit</a>
<div id="popup1" class="overlay">
<div class="popup">
<table>
<tr>
<img class="output" id="output" >
<td colspan="2" align="center"><input type="file" value="Upload Photo" accept="image/*" onchange="openFile(event)" name="img" id="img"><p id="imgtext"></p></td></tr>
</table>
<input type="submit" class="update" value="Update Form" >
</div></div></div></form>
<script>
        function myFunction()
        {
            document.getElementById("textname").value="<%=rst.getString("Te_Name")%>";
            document.getElementById("dob").value="<%=rst.getString("Te_DOB")%>";
            document.getElementById("mobilenumber").value="<%=rst.getString("Te_Mobile")%>";
            document.getElementById("adharnumber").value="<%=rst.getString("Te_AadharNumber")%>";
            document.getElementById("gender").value="<%=rst.getString("Te_Gender")%>";
            document.getElementById("scuid").value="<%=rst.getString("Sc_UID")%>";
            document.getElementById("busno").value="<%=rst.getString("Bus_Number")%>";
            document.getElementById("password").value="<%=rst.getString("Te_password")%>";
            var sr="<%= rst.getString("Te_Photo")%>";
            document.getElementById("output").src="filename/"+sr;
            var url=
            document.getElementById("output").src.innerHTML="teacher/"+sr;

        }
        var openFile = function(event) 
    {
        var input = event.target;
        if(input.files[0].size>1024*1024)
        {
            document.getElementById("imgtext").innerHTML="File Size Should be Less Than 1 MB";
            var output = document.getElementById('output');
            output.src = "";
            input.value="";
        }
        else
        {
            var reader = new FileReader();
            reader.readAsDataURL(input.files[0]);
            reader.onload = function()
            {
                var dataURL = reader.result;
                var output = document.getElementById('output');
                output.src = dataURL;
            };
        }
    }
    </script>
````
````    

Output should have the the photo as well as the url of that photo in boxes.

0 个答案:

没有答案