0

I want to send values of my textfields of JSP/HTML page through URL like this:

<a href="some.jsp?uname=Somnath&dob=02/02/89&gender=male"></a>

But instead of static value I need to send the value which is putted currently.
Actually I want to receive the value of all fields by getParameter() method. But we can not use:

<form action="someAnother.jsp" method="post">

Because there is anothere URL attached with the form.Actual Situation is:

<form action="someAnother.jsp" method="post">
  <input type='text' name='uname'/>
  <input type='password' name='password'/>
  <input type='text' name='dob'/>
  <input type='text' name='contact'/>
  <a href="some">
    <input type='button' value='Upload Image'/>
  </a>
  <input type='submit' value='Register'/>
</form>

UploadImage Button call a servlet & make some operations and forward to this page again. And I need to fill all fields again which was filled by the user before hit the Upload Image Button.
So I think only way to get those values in that servlet is through URL.Please give me your suggestion.

  • Remind that we can get all the field values in a JSP/Servlet only if we make the action through form tag & also remind the nested form is not allowed.
  • So only way to call another servlet/jsp within a form tag again is a tag but it Carries no data with it.If i want to send some data with a tag then we have to use URL like firs Example.
Somnath Kayal
  • 393
  • 2
  • 9
  • 25

3 Answers3

1

Alternative 1:

Change

method="post"

to

method="get"

Alternative 2: Submit the above form data to a servlet (BasicInfoServlet). In this servlet, save the received data in session and the redirect/forward the user to image upload page. Submit the image upload form to a second servlet (ImageInfoServlet). In the second servlet write code to save/process the image and initial data from session.

Apurv
  • 3,723
  • 3
  • 30
  • 51
0

Use "get" method.

Code :-

<form action="/servleturl_mappingpath" method="get">
  <input type='text' name='uname'/>
  <input type='password' name='password'/>
  <input type='text' name='dob'/>
  <input type='text' name='contact'/>
  <a href="some">
    <input type='button' value='Upload Image'/>
  </a>
  <input type='submit' value='Register'/>
</form> 

If you method is get, the requested data will be visible on URL.

When you click on Register Button, the request will go to the given servlet ( /servleturl_mappingpath) .

Now, you can get in servlet as below :

String namee=request.getParameter("uname"); 
String pass=request.getParameter("password"); 
String dobb=request.getParameter("dob"); 
String contactt=request.getParamenter("contact");

Use the above code in your servlet. And finally redirect your response to any given JSP.

Hope it will help you.

JDGuide
  • 6,239
  • 12
  • 46
  • 64
0

Use POST method and the enctype attribute of the form has to be set to "multipart/form-data"

Check this post
https://stackoverflow.com/a/2424824/2106973

OR

Tutorial for Java servlet upload file
http://www.servletsuite.com/servlets/upload.htm

Community
  • 1
  • 1
Navnath Godse
  • 2,233
  • 2
  • 23
  • 32