0

Here i need to add a product to a database but i dont know how to save the image to disk and return the saved location so i can save that in the database... here is my 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" %>

as you can see i have a image input there. how do i get the image in my java... here is my 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;
}

there are getters and setter for all variables but i didn't add them here

but how do i save the image on the server and return the saved location so i can add that in the database???

hunteroooox
  • 115
  • 1
  • 11

1 Answers1

0

Found it: https://cwiki.apache.org/confluence/display/WW/File+Upload

here was everything i needed

hunteroooox
  • 115
  • 1
  • 11