簡體   English   中英

如何將圖像保存到磁盤並使用java / jsp檢索圖像

[英]how to save an image to disk and retrive it with java/jsp

在這里,我需要將產品添加到數據庫,但是我不知道如何將圖像保存到磁盤並返回保存的位置,以便可以將其保存在數據庫中……這是我的addProduct.jsp

<%@include file="../includes/layout.jsp" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<script>
var PageName = "ProductToevoegen";
</script>
<div class="col-lg-12">
    <s:form action="addProduct">
        <table class="table table-striped table-bordered declarations-table responsive">
        <thead>
        <th class="paddingLeft"><h1>Product toevoegen</h1></th>
        <th class="paddingLeft"><h1>Input</h1></th>
        </thead>
        <tbody>
            <tr>
                <td class="paddingLeft">Naam</td>
                <td class="paddingLeft"><input type="text" id="productName" name="productName"><br><br></td>
            </tr>
            <tr>
                <td class="paddingLeft">Foto</td>
                <td class="paddingLeft"><input type="file" id="image" name="image" accept="image/*"/><br><br></td>
            </tr>
            <tr>
                <td class="paddingLeft">Beschrijving</td>
                <td class="paddingLeft"><input type="text" id="description" name="description"><br><br></td>
            </tr>
            <tr>
                <td class="paddingLeft">Prijs</td>
                <td class="paddingLeft">$<input type="number" id="price" name="price"><br><br></td>
            </tr>
            <tr>
                <td class="paddingLeft">Voorraad</td>
                <td class="paddingLeft"><input type="number" id="stock" name="stock"><br><br></td>
                    <s:submit value="submit" />
            </tr>
        </tbody>
    </table>
</s:form>
</div>
<%@include file="../includes/footer.jsp" %>

如您所見,我在那里有圖像輸入。 我如何在Java中獲取圖像...這是我的shopController.java:

private ArrayList<Product> producten;
private int id;
private String productName;
private String image;
private String description;
private int price;
private int stock;


public String addProduct() {
    //imageLocation = image.
    Product p = new Product(0, imageLocation, productName, description, price, stock);
    DAOProduct.getInstance().createProduct(p);
    return SUCCESS;
}

所有變量都有getter和setter方法,但我沒有在此處添加它們

但是如何將圖像保存在服務器上並返回保存的位置,以便可以將其添加到數據庫中?

找到了它: https : //cwiki.apache.org/confluence/display/WW/File+Upload

這就是我需要的一切

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM