Hi Ann, I'm not sure I got your problem. I think if you POST your form the userId parameter will not be recognized by your servlet. So you need to add the userID into the form. Just use a hidden form field. Then it is just a standard submit. Regards Torsten
Hi Torsten Schippel & Sudhakar Reddy Konda thanx for ur help....but i try both of ur ways, still cannot....i can get the userid without having a hidden form but i can't get the fileName1. I did try many ways in the servlet to get the parameter but it return a null, i tink it doesn't pass in the value into the servlet. does anybody noe how to concaterate the string url with the fileName1??? Thanx in advance!!!
Your problem may not be in submitting the data but in retrieving the data. The fact that you are using a mutli-part form complicates matters quite a bit. What are you using to parse the multi-part form? That may be where the problem lies. bear [ September 25, 2003: Message edited by: Bear Bibeault ]
If I understand clearly what you are trying to do is to uplad a file; basically the value in the textfield fileName1 is the name of the file to be uploaded. I advice you get a handle to the JSP file say jspRef and use the method getFileName() ie jspRef.getFileName() to get the value of the text field fileName1...getFileName() returns a string which is the name of the file to be uploaded. Anselm Paulinus
Hi Bear Bibeault & Anselm Paulinus, thanx for ur help... To Bear Bibeault, i ready hav prob in retrieving the data...i am using MultipartRequest to upload the file. To Anselm Paulinus,
i hav try ur method but i still doesn't work. i tink it is the concaterate part. i wan to concaterate the fileName1 with the string url below. but how do i concaterate?? <% String userId = (String) session.getAttribute("theName"); String url = "http://localhost:8080/SDC1/servlet/parserupload?Username="+userId; %> <div id="Layer8" style="position:absolute; width:753px; height:115px; z-index:9; left: 142px; top: 270px;"> <FORM name="form1" ACTION=<%=url%> METHOD="POST" ENCTYPE="multipart/form-data"> Thanx in advance...
[ September 25, 2003: Message edited by: Ann Toh ]
Hi Ann, I just tested your problem. It was a little strange to me. If I add a paramter to the URL, use POST method and ENCTYPE="multipart/form-data" I can access the added parameter through getParameter(..) but I can not access any other paramters which are part of the form (as expected because of encoding). If you already use a multipartrequest class then it should be able to return the filename (all form parameters). Check http://www.servlets.com/cos/javadoc/com/oreilly/servlet/MultipartRequest.html But there are many others out there. To have a clean design I would use a hidden field anyway. Just to separate normal GET and POST methods. Regards Torsten
Sainudheen, I'm not sure how that link is relevant. Ann, as Torsten already mentioned, you *must* use a special handler for multipart/form-data. The usual method of retrieving parameters by calling request.getParameter("foo") WILL NOT WORK with multipart/form-data. The reasons are complicated but if you do a Google search for "multipart/form-data" and JSP you will find plenty of explanations/tutorials on why this is so. If you want access to all your form parameters as well as the file you are uploading, you MUST use a library like Torsten has provided to retrieve the data from the request. In fact, this is the library I use myself. [ September 28, 2003: Message edited by: Rob Ross ]
Hi Torsten Schippel, I can get the filename from the multipartrequest method but i wan to check whether the textfield is empty before i upload the files. When i uploading the files, i will first delete all the files in that directory. so at this moment, when i upload a file, the 1st thing i do is to delete the files in tat directory then i upload the file and when the textfield is empty, it still delete away the existing files in the directory and return an error message. Can anyone tell me how?? thanx in advance...
Hi Torsten Schippel and everyone, thanx for all ur help...now i can solve my prob already. this is what i do, first i upload the files, then i get the filename from the MultipartRequest method. next i delete all the files in the directory except the files that i juz upload in it. finally, solve the prob... thanx everyone
I’m tired of walking, and will rest for a minute and grow some wheels. This is the promise of this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss