| Home | JSP | EJB | JDBC | Java Servlets | WAP | Free JSP Hosting | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML | ||||
|
||||
|
|
||||
| Tutorial Categories: Ajax
| Articles
| JSP
| Bioinformatics
| Database
| Free
Books |
Hibernate
| J2EE
| J2ME
| Java
| JavaScript
| JDBC
| JMS
| Linux
| MS
Technology |
PHP
| RMI
| Web-Services
| Servlets
| Struts
| UML
|
|
||||||||||||||||||||||||||||||
|
Home | JSP | EJB | JDBC | Java Servlets | WAP | Free JSP Hosting | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs |
||||||||||||||||||||||||||||||
Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.
Copyright © 2007. All rights reserved.
Current Comments
1 comments so far (post your own) View All Comments Latest 10 Comments:hi...
sorry for late reply...i am writing a program for uploading files...that i got.but in the form one textbox values and memu list is included for company name and category level..if i am writing the company name in textbox and category level as level1,level2 etc.then this values is also automatically writing into that uploading file...when the encryption type is set as multipart/form data then the textbox value is not taken..otherwise no uploading is worked..but the text value is null..here is my code
<%@ page import="java.beans.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.io.*,javax.servlet.http.HttpServletRequest,javax.servlet.ServletInputStream"%>
<%@ page import="java.io.FileWriter,java.io.IOException "%>
<%@ page contentType="text/html"%>
<html>
<head>
<title>
</title>
</head>
<body>
<p>
<%
try
{
String cname=request.getParameter("cname");
out.println(cname);
String category=request.getParameter("category");
out.println(category);
String ss="welcome";
byte[] buf1=new byte[1024];
buf1=ss.getBytes();
String contentType = request.getContentType();
System.out.println("Content type is :: " +contentType);
if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
DataInputStream in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();
byte dataBytes[] = new byte[formDataLength];
int byteRead =0;
int totalBytesRead =0;
while (totalBytesRead < formDataLength)
{
byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
totalBytesRead += byteRead;
}
String file = new String(dataBytes);
String saveFile = file.substring(file.indexOf("filename=\"") + 10);
//out.print("FileName:" + saveFile.toString());
saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
//out.print("FileName:" + saveFile.toString());
saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));
//out.print("FileName:" + saveFile.toString());
//out.print(dataBytes);
int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex + 1,contentType.length());
//out.println(boundary);
int pos;
pos = file.indexOf("filename=\"");
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
int boundaryLocation = file.indexOf(boundary, pos) - 4;
int startPos = ((file.substring(0, pos)).getBytes()).length;
int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
saveFile = "C:\\Program Files\\Apache Software Foundation\\Tomcat 5.5\\webapps\\ROOT\\textfile\\textdir\\" + saveFile;
FileOutputStream fileOut = new FileOutputStream(saveFile);
//fileOut.write(dataBytes);
fileOut.write(dataBytes, startPos, (endPos - startPos));
/*if(submit!=null)
{
String strPath = "C:\\\\Program Files\\\\Apache Software Foundation\\\\Tomcat 5.5\\\\webapps\\\\ROOT\\\\textfile\\\\textdir\\\\" + saveFile;
File strFile = new File(strPath);
Writer objWriter = new BufferedWriter(new FileWriter(strFile));
objWriter.write(cname );
objWriter.write(category );
objWriter.flush();
objWriter.close();
}*/
fileOut.write(buf1);
fileOut.flush();
fileOut.close();
out.println("File saved as " +saveFile);
}
}
catch(Exception e)
{
}
finally
{
out.println();
}
%>
</p>
<p> </p>
</body>
</html>
and design page is
<html>
<head>
<title>
</title>
</head>
<body>
<p> </p>
<p> </p>
<form name="form1" method="post" action="form2">
<p> </p>
<p>
<label>Company Name<br>
<input name="cname" type="text" id="cname">
</label>
</p>
<p>
<label>Category
<select name="category" id="category">
<option>Level1</option>
<option>Level2</option>
<option>Level3</option>
<option>Level4</option>
<option>Level5</option>
</select>
</label>
<label></label>
</p>
<p>
<input type="submit" name="Submit" value="upload" onClick="store6.jsp">
<label>
<input type="reset" name="Submit2" value="reset">
</label>
</p>
<p> </p>
</form>
<form action="store6.jsp" method="post" enctype="multipart/form-data" name="form2">
<table width="438">
<tr>
<td>Select a File to upload </td>
</tr>
<tr>
<td><label>
<input type="file" name="file" />
</label></td>
</tr>
<tr>
<td><label>
<input name="Upload" type="submit" id="Upload" value="Upload" />
</label>
<label>
<input name="reset" type="reset" id="reset" value="Reset" />
</label></td>
</tr>
</table>
<p> </p>
<p> </p>
</form>
<p> </p>
<br>
</body>
</html>
Posted by ashitha on Wednesday, 05.23.07 @ 14:02pm | #17076