Upload using Jsp
Upload Form
<%@ page language="java" contentType="text/html;charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPEhtml PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<form action="UploadHandler.jsp" enctype="multipart/form-data">
<tablewidth="60%" border="0" cellspacing="1" cellpadding="1" align="center" class="style1">
<tr>
<tdalign="left"><b>Select a file to upload :</b></td>
</tr>
<tr>
<tdalign="left">
<inputtype="file" name="filename" size="50">
</td>
</tr>
<tr>
<tdalign="left">
<inputtype="hidden" name="todo" value="upload">
<inputtype="submit" name="Submit" value="Upload">
<inputtype="reset" name="Reset" value="Cancel">
</td>
</tr>
</table>
</form>
</body>
</html>
Upload Handler
<%@ page import="java.util.*,java.io.*"%>
<%
String path = request.getParameter("filename");
String newPath = "";
int count = 0;
out.println("1.File1 Uploaded from :: " + path);
if (path != null) {
ArrayList arr = new ArrayList();
StringTokenizer st = new StringTokenizer(path, "\\");
while (st.hasMoreTokens()) {
arr.add(count, st.nextToken());
count++;
}
// create ur own path
newPath = "c:/Harshal/" + arr.get(count - 1);
int c;
FileInputStream fis = new FileInputStream(path);
FileOutputStream fos = new FileOutputStream(newPath);
while ((c = fis.read()) != -1) {
fos.write((char) c);
}
}
out.println("<br>");
out.println("<br>");
out.println("1.File1 Uploaded from :: " + path);
out.println("<br>");
out.println("<br>");
out.println("2.Uploaded File1 is Saved in :: " + newPath);
%>
Upload Form
<%@ page language="java" contentType="text/html;charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPEhtml PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<form action="UploadHandler.jsp" enctype="multipart/form-data">
<tablewidth="60%" border="0" cellspacing="1" cellpadding="1" align="center" class="style1">
<tr>
<tdalign="left"><b>Select a file to upload :</b></td>
</tr>
<tr>
<tdalign="left">
<inputtype="file" name="filename" size="50">
</td>
</tr>
<tr>
<tdalign="left">
<inputtype="hidden" name="todo" value="upload">
<inputtype="submit" name="Submit" value="Upload">
<inputtype="reset" name="Reset" value="Cancel">
</td>
</tr>
</table>
</form>
</body>
</html>
Upload Handler
<%@ page import="java.util.*,java.io.*"%>
<%
String path = request.getParameter("filename");
String newPath = "";
int count = 0;
out.println("1.File1 Uploaded from :: " + path);
if (path != null) {
ArrayList arr = new ArrayList();
StringTokenizer st = new StringTokenizer(path, "\\");
while (st.hasMoreTokens()) {
arr.add(count, st.nextToken());
count++;
}
// create ur own path
newPath = "c:/Harshal/" + arr.get(count - 1);
int c;
FileInputStream fis = new FileInputStream(path);
FileOutputStream fos = new FileOutputStream(newPath);
while ((c = fis.read()) != -1) {
fos.write((char) c);
}
}
out.println("<br>");
out.println("<br>");
out.println("1.File1 Uploaded from :: " + path);
out.println("<br>");
out.println("<br>");
out.println("2.Uploaded File1 is Saved in :: " + newPath);
%>
No comments:
Post a Comment