This is my html code for <form>
<form action="<%= request.getContextPath() %>/admin/company/add" id="add-form" name="add-form" method="post" enctype="multipart/form-data">
<textarea class="form-control" name="name" placeholder="Name" ></textarea>
<textarea class="form-control" name="address" placeholder="Address" ></textarea>
<input class="form-control" name="contact_person" placeholder="Contact Person" type="text" >
<input class="form-control" name="email" placeholder="Epost" type="email" >
<input class="form-control" name="web" placeholder="Website url" type="text">
<input class="form-control" name="phone" placeholder="Phone" type="text" >
<input class="form-control" placeholder="Telefax" name="telefax" type="text" >
<button type="submit" class="btn green btn-outline"><i class="fa fa-check"></i> Save</button>
</form>
and this is my code in servlet's doPost()
method
CompanyEntity companyEntity = new CompanyEntity();
companyEntity.setAddress(request.getParameter("address"));
companyEntity.setName(request.getParameter("name"));
companyEntity.setEmail(request.getParameter("email"));
companyEntity.setWeb(request.getParameter("web"));
companyEntity.setContactPerson(request.getParameter("contact_person"));
companyEntity.setPhone(request.getParameter("phone"));
companyEntity.setTelefax(request.getParameter("telefax"));
Error- All values to the entity are null
what's the error here, how to fix it.
You're posting the form as multipart/form-data
. Since it doesn't seem like you're uploading any files, change it to application/x-www-form-urlencoded
(or remove it altogether since this is the default).
Alternatively, add some sort of multipart request filter/wrapper to your application so that it processes multipart requests and provides access to the request parameters.
从您的from标记中删除enctype="multipart/form-data"
表单中的输入名称为“ fax”,但您写为
request.getParameter("telefax")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.