【发布时间】:2020-07-21 13:54:48
【问题描述】:
我想在数据库中上传一张图片,这是我的jsp:
<body>
<form action="addbooka" method="POST" enctype="multipart/form-data">
Title:<input type="text" value="${title}" name="title"> <br>
Description: <input type="text" value="${description}" name="description"><br>
Price: <input type="text" value="${price}" name="price"><br>
Picture: <input type="file" name="myimg"><br>
<button type="submit">Add</button>
</form>
</body>
这是我insert图片的方法:
public static void insertImage(String myImage) throws Exception {
try {
String insertImage = ("insert into image(image) values(?)");
PreparedStatement ps = DataBaseConnection.get().prepareStatement(insertImage);
File file = new File(myImage);
InputStream in = new FileInputStream(file);
ps.setBlob(1, in);
ps.executeUpdate();
在 servlet 中,我只需调用此方法并将 request.getParameter("myimg") 作为参数(输入标记)传递。
经过一些研究,我认为我得到了这个错误,因为我没有把boundary 放在form 标签中。但我不知道该放什么数字,下一步该做什么,还是因为边界或其他原因而真的出错了?
【问题讨论】:
标签: sql jsp exception servlets file-upload