Im developing a simple file upload using JSP, everything works fine until I set the form's enctype to "multipart/form-data", request.getParameterNames()
is returning empty. Any idea?
Here's my code:
upload.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>File Upload</title>
</head>
<body>
<form method="POST" action="login.jsp" enctype="multipart/form-data">
<input type="text" name="name" placeholder="File Name"></input>
<br>
<input type="file" name="file" id="file"></input>
<br><br>
<input type="submit" name="submit" id="submit" value="Submit"></input>
</form>
</body>
</html>
login.jsp
<%@page import="java.util.Enumeration"%>
<%@page import="java.io.InputStream"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
Enumeration params = request.getParameterNames();
boolean empty = true;
while(params.hasMoreElements()){
String param = params.nextElement().toString();
out.println(param);
empty = true;
}
if(empty) out.println("No parameters received!");
%>
</body>
</html>