N
N
Nikolay Baranenko2017-01-30 07:58:42
JavaScript
Nikolay Baranenko, 2017-01-30 07:58:42

How to correctly pass the value of the INPUT form element to the JAVA code?

Hello.

The jsp page
has an INPUT input element, there is a JAVA method Get_ID_WindowsService, which returns the ID of the Windows service

<input id = "service_name" value="termservice" />


<%!
public String Get_ID_WindowsService(String serviceName) throws UnsupportedEncodingException {
String executeCmd = "cmd /c sc queryex \"" + serviceName + "\"";
String line;
Process runtimeProcess;
 String Response = "";
        try {
            runtimeProcess = Runtime.getRuntime().exec(executeCmd);
            BufferedReader input = new BufferedReader(new InputStreamReader(runtimeProcess.getInputStream(),"cp866"));
int processComplete = runtimeProcess.waitFor();
            while ((line = input.readLine()) != null) {
                Response = Response + "\n" + line;
            }
            input.close();
  int start = Response.indexOf("ID_процесса");
  if (start < 0)
    start = Response.indexOf("PID");
  String status = "Error";
  if (start > 0)
  {
    status = Response.substring(start, Response.indexOf('\n',start)).trim();
    status = status.split(" ")[status.split(" ").length-1];
  }
Response=status;
        } catch (Exception e) {
            Response=Runtime.class.getName() + " (" + e.getClass().getName() + ") " + e.getMessage();
            return Response;
        }
        return Response;
  }
%>


there is a button

<input type="button" id="get_id_service" value="Получить PID" />


on pressing, which would like the information from INPUT to go to the JAVA method Get_ID_WindowsService and the result was displayed on this page, preferably without reloading.
What is the best way to do this?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question