Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #35120

How to upload a file with jsp?

From parmenides <xparmenides@yahoo.com>
Newsgroups comp.lang.java.programmer
Subject How to upload a file with jsp?
Date 2016-07-24 10:25 +0800
Organization Aioe.org NNTP Server
Message-ID <nn18vh$1jll$1@gioia.aioe.org> (permalink)

Show all headers | View raw


Hi,

I have a requirment for my website with Java Server Page to upload a 
client file whose path is specified in a form. After uploaded, the file 
should be named after a person's job id and his name it the sever. For 
example, suppose that in the client, the name of the file to be uploaded 
is 'sth.zip', the id and the name of the person who upload the file are 
'12345' and 'tom', then in the server the uploaded file's name should be 
'12345.tom.zip'.

I have designed a form in a page like this:

<form action="" method="post" enctype="multipart/form-data">
	id:   <input type="text" id="id" name="id" >
	name: <input type="text" id="name" name="name" >
	file: <input type="file" id="file" name="file" >
	<input type="submit" name ="submit" >
</form>

And then, I need write some jsp code to deal with the request from the 
above form. Unfortunately, I encountered two situations confict with 
each other. On the on hand, owing to 'multipart/form-data' is specified 
in the attribute 'enctype' of the form, the file can be tranferred 
correctly. But, in jsp code, the parameter 'id' and 'name'can not be 
obtained with 'request.getParameter()'. Therefore, the file name can not 
be named after 'id' and 'name'. I think this case results from the 
encoding type of the form (namely 'multipart/form-data').

On the oter hand, if I remove the "multipart/form-data" from the form 
like this:

<form action="" method="post" >
	...
</form>

'id' and 'name' can be obtained by 'request.getParameter()', while the 
file can not be uploaded correctly (the file size is zero).

A natual idea is to take two separate forms, one is for submitting id 
and name, the other for transfering file. But I think this scheme is so 
clumsy. An alternative scheme is to use FTP to upload file, rather than 
HTTP's file transferring. But this scheme requires applet running in 
browser which further require JVM in client. Obviously, this make 
deployment more difficult.

Is there any suggestion? Thanks a lot.

Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

How to upload a file with jsp? parmenides <xparmenides@yahoo.com> - 2016-07-24 10:25 +0800
  Re: How to upload a file with jsp? Arne Vajhøj <arne@vajhoej.dk> - 2016-07-23 23:11 -0400

csiph-web