• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to pass more than 1 parameters into the sevlet???

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
i have problem in passing 2 parameters into my servlet. can i write a JSP script inside a javascript??
below r part of my codes...
<%
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">
<table bgcolor="#ECDFCE" border="0" width="100%">
<tr>
<td width="643" > <strong><font color="#65226A" face="Verdana, Arial, Helvetica, sans-serif">Which
file to upload?</font></strong><font face="Verdana, Arial, Helvetica, sans-serif"> 
</font><font face="Georgia, Times New Roman, Times, serif">
<input type="FILE" name="fileName1" size="60">
</font> </td>
</tr>
.
.
.
can anybody tell me how to pass the textfield "fileName1" to action in the form?? If can, can show me an example.
Thanx in advance!!!
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try
request.getParameter("filename1")
in servlet to get value of filename1 filed
 
Ann Toh
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!!
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 390
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Anselm Paulinus
Ranch Hand
Posts: 390
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops; since the name of your field is fileName1 or so; it should read jspRef.getfileName1() and not jspRef.getFileName().
Anselm
 
Ann Toh
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ann Toh
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
can anybody tell me how to pass a textfield value to a JSP scriptlet???
Thanx in advance...
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
did u tried using request.getparameter("txtBoxName");
 
Ann Toh
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi SaSaS,
i did try that method, but it return a null. It does not pass in the value into the servlet. Do u hav any other method to do??
Thanx in advance....
 
Torsten Schippel
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Have a look at this
----------
Sainudheen
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ann Toh
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ann Toh
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic