это мой JSP:
<div>
<b>${reply}</b>
</div>
<form action="runCommand" method="post" name="myform">
File:<input name="commandfile" type="text" size="10" value=${commandfile}> </input><br />
Command:<input name="commandinput" type="text" size="10" value=${commandinput}> </input><br />
No delete File: <input type="checkbox" name="no_del_file" value=${no_del_file} ><br>
<input name="submit" type="submit" value="Submit" />
<input name="Reset" type="reset" value="Reset" />
</form>
А это мой код сервлета Java:
public class RunCommand extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 5711290708294275382L;
String commands = null;
File dir = null;
BufferedReader is = null;
BufferedReader es = null;
boolean retval = false;
int testwin = 0;
int fileok = 0;
String completefilename = null;
File filecheck = null;
private BufferedReader outfile;
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
request.setAttribute("commandfile", "commandfile");
request.setAttribute("commandinput", "commandinput");
request.setAttribute("no_del_file", "no_del_file");
HttpSession session = request.getSession();
ServletContext application = getServletContext();
performTask(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
performTask(request, response);
}
private int getWin() {
Process Checkprocess;
try {
String Checkcommand = "cmd /c tasklist /V /FI \"WINDOWTITLE eq Administrator:*\"";
Checkprocess = Runtime.getRuntime().exec(Checkcommand);
String Checkline;
String Checkval = "Administrator:";
is = new BufferedReader(new InputStreamReader(Checkprocess.getInputStream()));
while ((Checkline = is.readLine()) != null) {
retval = Checkline.contains(Checkval);
if (retval = true) {
testwin = 1;
break;
} else
testwin = 0;
}
} catch (IOException e) {
e.printStackTrace();
}
return testwin;
}
private int getFile() {
filecheck = new File(completefilename);
while (fileok == 0) {
if (filecheck.exists()) {
fileok = 1;
break;
}
}
return fileok;
}
private void performTask(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
String commandbuild = request.getParameter("commandinput");
String commandfilename = request.getParameter("commandfile");
String[] no_del_file = request.getParameterValues("no_del_file");
final SimpleDateFormat datefor = new SimpleDateFormat("ddMMyyyy_HHmmss");
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
String timeadd = datefor.format(timestamp);
completefilename = "C:\\tmp\\" + commandfilename + "_" + timeadd + ".txt ";
String commandfull = "db2 -tvz " + completefilename + commandbuild;
commands = "cmd /c db2cwadmin.bat " + commandfull;
Process process;
process = Runtime.getRuntime().exec(commands);
String line;
StringBuilder data = new StringBuilder();
is = new BufferedReader(new InputStreamReader(process.getInputStream()));
data.append("Befehl: " + commands);
data.append("\n\n\n");
while ((line = is.readLine()) != null) {
data.append(line);
data.append("\n");
}
es = new BufferedReader(new InputStreamReader(process.getErrorStream()));
while ((line = es.readLine()) != null)
System.err.println(line);
int exitCode = -100;
exitCode = process.waitFor();
if (exitCode == 0) {
System.out.println("It worked");
while (testwin != 1) {
getWin();
if (testwin == 1) {
break;
}
}
while (fileok != 1) {
getFile();
if (fileok == 1) {
break;
}
}
Process EndProcess;
String Endcommands = "taskkill /F /FI \"WINDOWTITLE eq Administrator:*\"";
EndProcess = Runtime.getRuntime().exec(Endcommands);
int exitCodeEnd = -100;
exitCodeEnd = EndProcess.waitFor();
while (exitCodeEnd != 0) {
EndProcess = Runtime.getRuntime().exec(Endcommands);
exitCodeEnd = EndProcess.waitFor();
if (exitCodeEnd == 0) {
break;
}
}
// TimeUnit.SECONDS.sleep(10);
data.append("Fenster wurde geschlossen!");
data.append("\n");
data.append("\n");
File filecheck = new File(completefilename);
if (filecheck.exists())
outfile = new BufferedReader(new FileReader(completefilename));
String outfilelines;
while ((outfilelines = outfile.readLine()) != null) {
data.append(outfilelines);
data.append("\n");
}
request.setAttribute("data", data);
out.append(data);
outfile.close();
if (no_del_file == null) {
filecheck.delete();
}
request.setAttribute("commandfile", commandfilename);
System.out.println(commandbuild);
request.setAttribute("commandinput", commandbuild);
request.setAttribute("no_del_file", no_del_file);
HttpSession session = request.getSession();
ServletContext application = getServletContext();
RequestDispatcher dispatcher = request.getRequestDispatcher("/runCommand.jsp");
dispatcher.forward(request, response);
} else
System.out.println("Something bad happend. Exit code: " + exitCode);
} // try
catch (Exception e) {
System.out.println("Something when wrong: " + e.getMessage());
e.printStackTrace();
} // catch
finally {
if (is != null)
try {
is.close();
} catch (IOException e) {
}
if (es != null)
try {
es.close();
} catch (IOException e) {
}
} // finally
retval = false;
testwin = 0;
fileok = 0;
completefilename = null;
}
}
Проблема в том, что задано только первое слово. Поэтому, если команда (я заполняю ввод команд этим):
list applications
Я только получаю
list
вернуться в командное поле, и флажок также не установлен, если он был установлен перед отправкой.
Таким образом, в поле ввода команды форвард обрезает все слова после первого пробела, и флажок не устанавливается снова (проверка не сохраняется). Мне нужно заполнить форму так, как она была до отправки.
Есть идеи?
Спасибо