CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> Java

 Please any one help me to upload from client using jsp..

Print topic Send  topic

Author Message
senthil_seyyone

Posts: 4
Posted: 08/18/2007, 1:57 AM

hi. All


i am using j2EE server 1.4 for my intranet project. i want upload file and download file from client machine to server(Linex file system.). also better if possible download from linux server to client machine.. i want to know wheter it is possible in java or needs some other dll like ChilKat.dll to upload and download client.. please reply me as soon as possible..



View profile  Send private message
senthil_seyyone

Posts: 4
Posted: 08/18/2007, 2:46 AM

hi.
View profile  Send private message
negociant

Posts: 31
Posted: 08/20/2007, 2:34 AM

You can upload and download files without any dll or other.
Just use CCS Upload component.

And if you have any wxpirience with java you can create own servlets for upload or download if you need something special.
View profile  Send private message
senthil_seyyone

Posts: 4
Posted: 08/20/2007, 3:37 AM

hi..

i have tried this code..

<!-- upload.jsp -->

<%@ page import="java.io.*" %>

<%String contentType = request.getContentType();

String file = "";

String saveFile = "";

FileOutputStream fileOut = null;

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;

}

try {

file = new String(dataBytes);

saveFile = file.substring(file.indexOf("filename=\"") + 10);

saveFile = saveFile.substring(0, saveFile.indexOf("\n"));

saveFile = saveFile.substring(saveFile.lastIndexOf("/") + 1,saveFile.indexOf("\""));

int lastIndex = contentType.lastIndexOf("=");

String boundary = contentType.substring(lastIndex + 1,contentType.length());

int pos;

pos = file.indexOf("filename=/" + 1);

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;

String folder = "/tmp/";

fileOut = new FileOutputStream(folder + saveFile);

//fileOut.write(dataBytes);

fileOut.write(dataBytes, startPos, (endPos - startPos));
out.println("FileUploaded Succefully");

fileOut.flush(); } catch(Exception e) { out.print(e);

} finally

{ try

{fileOut.close();

}catch(Exception err)

{}

}

}



%>

its not working fine.. its only for upload in linux server.. its transfered successfully.. but its open fine when text file open. but word fine and audio fine. not opened clearly.. it contains some ascii values. i want to open clearly.. please help me.

Thanks and regards.
Senthil ..

View profile  Send private message
negociant

Posts: 31
Posted: 08/20/2007, 5:04 AM

1. Upload nad download it's 2 different processes.
2. For upload some file you don't need any custom or written manually code. Just use fileUpload component.
3. For donload from server you should adjust tomcat for this or use servlet which return file.

View profile  Send private message
senthil_seyyone

Posts: 4
Posted: 08/20/2007, 5:38 AM

hi..

please give some idea regarding CSS. what is that.. how can i use. still i did't use css..
give me some sample program. and how can i import in jsp page..

regards..

M.Senthil..
View profile  Send private message
Wkempees
Posted: 08/20/2007, 6:08 AM

Not CSS but CCS.
If you are not a CCS user, I suggest posting your Java questions
on one of the many Java forums.
This is a forum for CCS CodeCharge Studio Users using the Java flavour.

W.
senthil_sivanath

Posts: 5
Posted: 12/28/2007, 10:19 AM

The above file upload can be also done as

// Hi Fnds,
//This is the Simple Code that works well to upload any File Checkout


//Html Code for Browsing Purpose
<html>
<head>
<form action="NewUpload.jsp" name="upform" enctype="multipart/form-data">
<table width="60%" border="0" cellspacing="1" cellpadding="1" align="center" class="style1">
<tr>
<td align="left"><b>Select a file to upload :</b></td>
</tr>
<tr>
<td align="left">
<input type="file" name="filename" size="50">
</td>
</tr>
<tr>
<td align="left">
<input type="hidden" name="todo" value="upload">
<input type="submit" name="Submit" value="Upload">
<input type="reset" name="Reset" value="Cancel">
</td>
</tr>
</table>
</form>
</body>
</html>

//**************************************************************************//
// this is the JSP Code//


<%@ page import="java.util.*,java.io.*"%>

<%
String path=request.getParameter("filename");
String newPath="";
int count=0;

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:/Ravii/"+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("Thanks for using");
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);
%>


Regards,

Senthil
_________________
Arise, Awake and Stop not till your goal is reached
View profile  Send private message
jf2008

Posts: 2
Posted: 03/12/2008, 1:06 PM

You could try JSP Upload script sample at:
http://www.jfileupload.com/products/tools/index.html

If HTML form upload doesn't fit to your need then you could try an upload applet named JFileUpload. It could also work with the same JSP upload script:
http://www.jfileupload.com/products/jfileupload/index.html

I hope it helps.
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.