public class Relay extends HttpServlet {
@Override
public void service(HttpServletRequest request, HttpServletResponse response)
throws Servl
remove the form tag and use
echo <?php form_open_multipart('Controller/function');
I got the same issue whenever I use enctype="multipart/form-data"
I didn't get the file name and when I remove that it was working fine
try it it worked for me
Parameters encoded with multipart/form-data
are sent in POST body - not as regular request parameters, therefore can't be read using request.getParamter(...)
.
Check out Commons file upload package for multipart requests processing.
Why do you need to add it then? Just keep it out.
If you need it in order to upload a file by <input type="file">
which you intend to add later on, then you should put @MultipartConfig
annotation on your servlet, so that request.getParameter()
will work and that all uploaded files can be retrieved by request.getPart()
.
@WebServlet("/Relay")
@MultipartConfig
public class Relay extends HttpServlet {
// ...
}
I am including this just for additional information for troubleshooting. if you are stuck and want to know about what all parameters are coming through multipart request you can print all parameters using following code.
MultipartRequest multi = <Your code to retrieve multipart request goes here. Sorry but can not post code as I use proprietary APIs>
Enumeration en1 = multi.getParameterNames();
while (en1.hasMoreElements()) {
String strParamName = (String)en1.nextElement();
String[] strParamValues = multi.getParameterValues(strParamName);
for (int i = 0; i < strParamValues.length; i++) {
System.out.println(strParamName + "=" + strParamValues[i]);
}
}