File uploading with JSP

N

nicky

I have some problem about file upload with JSP. If I use form that
have multiple form fields, I can upload but can't get other field
values. So I want to know how to solve this. Anyone can help me?
Thanks.
 
K

kaeli

s4420765 said:
I have some problem about file upload with JSP. If I use form that
have multiple form fields, I can upload but can't get other field
values. So I want to know how to solve this. Anyone can help me?
Thanks.

The last I checked, there was no solution to this problem.
Let me know if you find one. The question has come up numerous times.

--
 
M

Murray

kaeli said:
The last I checked, there was no solution to this problem.
Let me know if you find one. The question has come up numerous times.

It it possible, but you can't just access them via request.getParameter
because that doesn't work with multipart requests. I take it you're writing
your own multipart parser? I attempted the same a while ago, until I found
the Commons File Upload package. Why bother rolling your own if someone else
has already done the hard & tedious work for you? ;-) Unless of course
you're up for a challenge, which I wasn't at the time ...

http://jakarta.apache.org/commons/fileupload/

Struts makes it even easier ...
 
B

Ben Jessel

I have some problem about file upload with JSP. If I use form that
have multiple form fields, I can upload but can't get other field
values.


Are you using multipart encoding in your form?

<form ENCTYPE="multipart/form-data">

Can you post your code?
 
K

kaeli

It it possible, but you can't just access them via request.getParameter
because that doesn't work with multipart requests. I take it you're writing
your own multipart parser?

Eeek, no.
*g*

I was just trying to answer the question of how to get text and an
upload at the same time in an ASP forum.
We never did find a way to do that.

Looks like there isn't a way without using a third party tool or writing
one...

--
 
M

Murray

Eeek, no.
*g*

I was just trying to answer the question of how to get text and an
upload at the same time in an ASP forum.
We never did find a way to do that.

Looks like there isn't a way without using a third party tool or writing
one...

Ah ok. But if you weren't writing your own parser, and not using a third
party tool, how were you doing it? Does ASP have some built-in upload
function? If it does, then it obviously doesn't implement the full spec
http://www.ietf.org/rfc/rfc1867.txt
 
K

kaeli

Ah ok. But if you weren't writing your own parser, and not using a third
party tool, how were you doing it?

I wasn't. ;)

It ended up being a two part form. One for the upload and one for the
rest.
I was hoping for a better solution.

--
 
S

Sudsy

kaeli wrote:
I wasn't. ;)

It ended up being a two part form. One for the upload and one for the
rest.
I was hoping for a better solution.

Murray made a good point. I never ran into your problem as I selected
the Struts framework. Everything is handled nicely; just cast the form
to your own class and go to town. Even the staging of the uploaded
files is managed intelligently.
Please don't cut me down for suggesting that you do some investigation
on such frameworks. Depending on the nature of your application, they
can be a huge time-saver. The learning curve is steep but there are
some good web resources available these days, unlike the early years.
I believe that it's worth the investment in time and effort...YMMV
 
K

kaeli

Murray made a good point. I never ran into your problem as I selected
the Struts framework. Everything is handled nicely; just cast the form
to your own class and go to town. Even the staging of the uploaded
files is managed intelligently.
Please don't cut me down for suggesting that you do some investigation
on such frameworks.

I would never do that. *g*

A post I made to one of these java groups a few days ago expressed the
fact that I wish I'd known about Struts when I started. Although, after
investigating, it looks like I couldn't have used it anyway. I'm stuck
with IPlanet 6 and it doesn't work with that, according to the docs. :(

I don't have the budget or the time to rewrite my previous stuff using a
different framework, but suggestions for future projects are always
appreciated. I have never done anything as complicated (complex?) as
Java before. My experience was with cold fusion and classic ASP. I learn
something new every day lurking around here. *smile*
If you know of an alternative to Struts that will work with IPlanet 6,
let me know.
(If it were up to me, we'd be using Tomcat, but it isn't up to me, so
telling me to use Tomcat would just make me feel sad that I can't use it
all over again. *LOL*)
Heck, I just finally figured out how to use Java Beans in my JSP and I
really like them, so point me to anything you think I might find useful
for my next project.
And I'm still trying to figure out the difference between beans and
taglibs, so if you know about that, feel free to enlighten me. *BG* They
seem the same to me. I've finally gotten them both to work and now that
I've gotten the beans to work, can't figure out why on earth I'd want to
use taglibs.

--
--
~kaeli~
Jesus saves, Allah protects, and Cthulhu thinks you'd make
a nice sandwich.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 
G

Grant Wagner

kaeli said:
I wasn't. ;)

It ended up being a two part form. One for the upload and one for the
rest.
I was hoping for a better solution.

I submit the multipart form containing the upload to a Perl script (which can
handle form inputs and multipart data in the same submission), which writes
the file, then builds a query string and outputs:

Location: http://server/path/to/the/file.jsp?param1=value1&param2=value2...

This basically does a 304 Redirect and the browser ends up on the JSP page.
file.jsp can then retrieve the values from the query string.

It's not pretty, but it works fine (as long as you don't need to carry a huge
amount of data over to file.jsp).
 
N

nicky

Murray said:
It it possible, but you can't just access them via request.getParameter
because that doesn't work with multipart requests. I take it you're writing
your own multipart parser? I attempted the same a while ago, until I found
the Commons File Upload package. Why bother rolling your own if someone else
has already done the hard & tedious work for you? ;-) Unless of course
you're up for a challenge, which I wasn't at the time ...

http://jakarta.apache.org/commons/fileupload/

Struts makes it even easier ...

Thanks for your introduction.I download them to learn now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

JSP 0
uploading a jsp page 3
Using a DTSX file with GoDaddy 0
JSP - My new upcoming JavaScript library 0
Help with Github??? 2
Uploading 4
Getting error message with code 1
Word matching with specific parameters 1

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,058
Members
48,769
Latest member
Clifft

Latest Threads

Top