JSP : latest JSTL, File Upload from web form Client to Server Question!
807588Jan 28 2009 — edited Feb 2 2009/*
I understand that within a JSP, It is possible to read a file from the Client by opening a Stream somehow.
How do I code, within jsp/servlet (non tag) java code inside <% %>
blocks, WITHOUT openening a new connection to the URL, an InputStream from a client web browser form, from a file upload coded using
<input type="file" name="file1"/> ?
I have previously achieved this quite simply with a FileInputStream
with the previous version of JSTL.
How may I do this with the latest version of JSTL, with this index.jsp?
-with a simple text file.
-with a Binary file (with DataInputStream)?
*/
//*****************************************************************************************************************************************************************************
<%--
Document : index
Created on : 27/01/2009, 3:08:32 PM
Author : Zachary Mitchell
--%>
<%@page contentType="text/html" 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>JSP Page</title>
</head>
<body>
<h1 align="center">Hello World!</h1>
<form name="form1" method ="POST" >
<table align="center">
<tr>
<td>
<input name="file1" type="file" align="center"></input>
</td>
</tr>
<tr>
<td>
<input type="submit" value="submit" action="index.jsp" ></input>
</td>
</tr>
</table>
</form>
<!--*********************************************************************** -->
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@page import = "java.io.*" %>
<c:if test="${pageContext.request.method=='POST'}">
<%
{
File fileName = new File(request.getParameter("file1"));
out.println(fileName.toString());
FileInputStream stream = new FileInputStream(fileName);
out.println(stream.toString());
}
%>
</c:if>
<!--*********************************************************************** -->
</body>
</html>