Answer the question
In order to leave comments, you need to log in
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;
}
%>
<input type="button" id="get_id_service" value="Получить PID" />
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question