I'm attempting to upload a file into a jsp and then use the file in some other code. My problem is that it comes into the servlet as an Object via the request.getAttribute() call so I don't know what to cast it to.
I have this code so far to try and test what it is but I'm getting a NullPointerException.
test.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Input Test</title>
</head>
<body>
<form action="InputServlet" method="POST">
<input type="file" name="file1">
<input type="submit" value="submit">
</form>
</body>
</html>
inputservlet.java
public class InputServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println(request.getAttribute("file1").getClass());
}
}
Is my understanding of whats going on flawed or am I just coding it up wrong?
Also I'm expecting the type to be Object so if anyone knows what I should cast it too that would be very helpful as well.