question
Servlet+JSP develops a javaWeb project, sends a request to the console and reports an error
detailed question
form core code
<form action="${pageContext.request.contextPath}/seller/addgoods" method="post">
</form>
Process class core code
@MultipartConfig
@WebServlet(name = "SellerAddGoodsServlet", value = "/seller/addgoods")
public class SellerAddGoodsServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
solution
Add enctype="multipart/form-data" attribute to form
form
<form action="${pageContext.request.contextPath}/seller/addgoods" method="post" enctype="multipart/form-data">
</form>
solve the cause
According to the error log, the error message is:
org.apache.tomcat.util.http.fileupload.impl.InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is application/x-www-form-urlencoded
This error indicates that the content type of the request is not multipart/form-data or multipart/mixed, but application/x-www-form-urlencoded, so the request cannot be parsed by file upload.
To solve this problem, you need to ensure that the correct enctype attribute is used to specify the encoding type of the form as multipart/form-data when sending the request. For example, adding enctype="multipart/form-data" to an HTML form:
Make sure that the form uses the correct enctype attribute when sending the request, and make sure that the server-side request processing code can correctly parse the multipart/form-data type request.
references
To solve the reason, refer to chatgpt
It’s not easy
to be original, please indicate the source
if it’s helpful to you, don’t forget to like it and support it