You have two possibilities here :
1) Java as a controller
From your Java Servlet, get the form data :
String Form_text_data = request.getParameter("text_input");
If there are many fields you can instantiate a StringBuilder (with all requested filed that you need) to get one string of all target field answer - be sure to make sanity check of those fields before adding them to your String Builder.
Then pass your String result from the string builder to the Runtime class which has an exec method :
StringBuilder Python_script_command = new StringBuilder("python PATH/TO/YOUR/PYTHON_SCRIPT.py");
Python_script_command.append(Form_text_data) // Repeat this as many time as you wish for each form fields, but be sure to make sanity check before to avoid any injections that you do not want
Process p = Runtime.getRuntime().exec(Python_script_command.toString());
You can read the output then by binding it in this way :
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
// read the output from the command
System.out.println("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
please see this article for more details :
http://alvinalexander.com/java/edu/pj/pj010016
2) Execute from a python API Framwork such as FLASK
You could also build a REST API directly in python and when the user submit the form you send it through a POST request to your python app
And then it is extremely simple to extract the data you need :
from flask import Flask, request
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
default_name = '0'
data = request.form.get('input_name', default_name) #here is an example on one data getter from a form field
see this answer for more details (How to get form data in Flask?)
then use this data directly in python, again be sur to make all kinds of sanity checks