Easy learning with example program codes

Jsoup get form parameters example

Let us discuss how to get form parameters using Jsoup API with the help of below example.

Follow the below steps:

1. Create a HTML file containing form with some input parameters.
2. Use parse(File in, String charsetName) method of Jsoup class which returns Document object after processing the file object.
3. Get form by using getElementById() method of Connection class.
4. Get input parameters of the form.
5. Iterate and process parameters.


import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
 * This class is used get meta data from HTML using Jsoup.
 * @author codesjava
public class JsoupGetParameter {
  public static void main(String args[]){
    Document document;
    try {
	//Get Document object after parsing the html file.
                     new File("D:\\JsoupParameterTest.html"),"utf-8");
	//Get the form by id.
	Element testForm = document.getElementById("testForm");
	//Get input parameters of the form.
	Elements inputElements = testForm.getElementsByTag("input"); 
	//Iterate parameters and print name and value.
	for (Element inputElement : inputElements) {
		String key = inputElement.attr("name");
		String value = inputElement.attr("value");
		System.out.println("Parameter Name: " + key);
		System.out.println("Parameter Value: " + value);
    } catch (IOException e) {


Parameter Name: name
Parameter Value: Richi
Parameter Name: password
Parameter Value: sahdev
Parameter Name: submit
Parameter Value: Submit

Download this example.
Previous Topic: Jsoup get metadata from HTML example.

Related Topics:

How to build java project using ant in eclipse?
JAXB marshalling – convert java object to xml example.
How to create pdf file in java using iText jar?
Generics class example.
OGNL in struts 2.
Hibernate One-to-One Mapping using xml.
Send inline image in email using JavaMail API.
Quartz 2 JobListener example.


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at


We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on

Copyright © 2019 CodesJava Protection Status SiteMap Reference: Java Wiki