I am doing some java web applications using eclipse, and I host the .war file on glassfish4 server in other PC.
I have written a jsp page, the jsp page needs the user to enter all kind of information and browse any kind of file (such as txt, or image file) and upload to the glassfish4 local server.
I have done a lot of searching on Google, and I couldn't found any solution on that, can you all help me on these?
This is my JSP page code :
<form action="uploadFile" method="POST" enctype="multipart/form-data">
<div class="card-body">
<h5 class="card-title">Equipment Request</h5>
<div class="form-group row">
<label for="reqEmail" class="col-sm-2 text-right control-label col-form-label">Requestor</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="reqEmail" name="reqEmail" disabled value="reggiezhiyi.lim@motorolasolutions.com">
</div>
<label for="ID" class="col-sm-1 text-right control-label col-form-label">Request ID</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="ID" name="ID" disabled value="0000001">
</div>
</div>
<div class="form-group row">
<label for="projectName" class="col-sm-2 text-right control-label col-form-label">Project</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="projectName" name="projectName" maxlength="50" placeholder="Enter the Project Name..">
</div>
</div>
<div class="form-group row">
<label for="contactNum" class="col-sm-2 text-right control-label col-form-label">Contact No.</label>
<div class="col-sm-3">
<input type="number" class="form-control" id="contactNum" name="contactNum" maxlength="50" placeholder="Enter the Phone Number">
</div>
</div>
<div class="form-group row">
<label for="manID" class="col-sm-2 text-right control-label col-form-label">Manager Core ID</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="manID" name="manID" maxlength="50" placeholder="Enter the Manager Core ID">
</div>
</div>
<div class="form-group row">
<label for="from" class="col-sm-2 text-right control-label col-form-label">Loan Date From</label>
<div class="col-sm-4 input-group">
<input type="text" class="form-control" id="datepicker-autoclose" placeholder="mm/dd/yyyy">
<div class="input-group-append">
<span class="input-group-text"><i class="fa fa-calendar"></i></span>
</div>
</div>
<label for="to" class="col-sm-1 text-right control-label col-form-label">To</label>
<div class="col-sm-4 input-group">
<input type="text" class="form-control" id="datepicker-autoclose1" placeholder="mm/dd/yyyy">
<div class="input-group-append">
<span class="input-group-text"><i class="fa fa-calendar"></i></span>
</div>
</div>
</div>
<div class="form-group row">
<label for="reason" class="col-sm-2 text-right control-label col-form-label">Reason for Loan</label>
<div class="col-sm-6">
<textarea rows="3" class="form-control" id="reason" name="reason"></textarea>
</div>
</div>
<div class="form-group row">
<label for="attach" class="col-sm-2 text-right control-label col-form-label">Attachment</label>
<div class="col-sm-6">
<div class="custom-file">
<label class="custom-file-label" for="validatedCustomFile" placeholder="Choose File.."></label>
<input type="file" class="custom-file-input" id="validatedCustomFile" name="validatedCustomFile" required>
</div>
</div>
</div>
<div class="form-group row">
<label for="comment" class="col-sm-2 text-right control-label col-form-label">Equiment Configuration</label>
<div class="col-sm-9">
<textarea rows="5" class="form-control" id="comment" name="comment"></textarea>
</div>
</div>
<div class="form-group row">
<label for="shipping" class="col-sm-2 text-right control-label col-form-label">Shipping Address</label>
<div class="col-sm-9">
<textarea rows="3" class="form-control" id="shipping" name="shipping"></textarea>
</div>
</div>
<div class="form-group row">
<label for="return" class="col-sm-2 text-right control-label col-form-label">Return Address</label>
<div class="col-sm-9">
<textarea rows="3" class="form-control" id="return" name="return" disabled>Motorola Solutions Penang</textarea>
</div>
</div>
<div class="form-group row">
<label for="inven" class="col-sm-2 text-right control-label col-form-label">Inventory List</label>
<div class="col-sm-8"></div>
<div class="col-sm-2">
<button type="button" class="btn btn-primary" onclick="addTable()">Add</button>
<button type="button" class="btn btn-danger" onclick="deleteTable()">Delete</button>
</div>
<br>
<!-- <div class="col-sm-2"></div> -->
<div class="col-sm-12">
<table class="table" id="tableList">
<thead>
<tr>
<th scope="col">Category</th>
<th scope="col">Item</th>
<th scope="col">Sales Model No.</th>
<th scope="col">Asset Tag</th>
<th scope="col">Serial No.</th>
<th scope="col">Quantity</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
<div class="border-top">
<div class="card-body">
<button type="submit" class="btn btn-primary">Submit</button>
<button type="button" id="test" class="btn btn-primary">Test</button>
<button type="reset" class="btn btn-info">Reset</button>
</div>
</div>
</form>
The action is directly pointed to a uploadFile.java and I have no idea how to upload the file into a database.
I have a couple question about uploading to database :
1. Upload the file directly to database
2. Upload the file to glassfish4 local server, and save the path into database
After uploading to database, I would like to retrieve the file, and let the other user to download it.
I would like to know which 1 is easier to achieve? And which 1 is the more correct approach.