1

ボタンを含む JSP ページを作成しており、コードをスクリプトレットに入れています。

実行後はすべて問題ありませんが、ページを更新すると、ボタンをクリックせずにコードが再度実行されます。だから私はこれを取り除きたいです。

これが私のjspコードです:

<%
 if (request.getParameter("btnSubmit") != null) //btnSubmit is the name of your       

     button,not id of that button.
   {

String className = request.getParameter("testclass");
System.out.println(className);
String[] command = {"CMD", "/C", "mvn -Dtest=" + className + " test"};
ProcessBuilder probuilder = new ProcessBuilder(command);

//You can set up your work directory
probuilder.directory(new File("C:\\Users\\Amira\\junoWorkspace\\TestProjectUI"));

Process process = probuilder.start();

//Read out dir output
java.io.InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
System.out.printf("Output of running %s is:\n", Arrays.toString(command));
while ((line = br.readLine()) != null) {
    System.out.println(line);
}

//Wait to get exit value
try {
    int exitValue = process.waitFor();
    System.out.println("\n\nExit Value is " + exitValue);
} catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
}
%>

    <html:file properties="tonFichier" name="tonForm"/>


    <p>   Please specify a Test :<br>
        <input type="file" name="testclass" size="40" >
    </p>
    <div>
        <input type="submit" id="btnSubmit" name="btnSubmit" value="Execute Test"/>

    </div>
  </form>
 </body>

任意のアイデアをいただければ幸いですありがとう

4

1 に答える 1

0

FORM方法はだと思いますGETFormとしてメソッドを作成する必要がありますPOST

<FORM action="....." method="post"> 

GET は、ブラウザが更新時に自動的にリクエストを作成できるようにするべき等リクエストです。一方、

POST は非冪等性であるため、ブラウザーは次のようなポップアップを表示できます。Do you want to submit the request again.

于 2012-07-12T07:56:14.197 に答える