刷新jsp页面后重复执行

时间:2012-07-12 07:51:44

标签: jsp scriptlet

我正在编写一个包含按钮的jsp页面,我将代码放在scriptlet中

运行后一切都很好,但是当我刷新页面时,代码会再次执行,而不会点击按钮。所以我想摆脱这个。

这是我的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>

任何想法都将受到赞赏 谢谢

1 个答案:

答案 0 :(得分:0)

我认为FORM方法是GET。您应该将Form方法设为POST

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

GET是幂等请求,它允许浏览器在刷新时自动发出请求。然而,

POST为非幂等,可让浏览器显示弹出询问类似Do you want to submit the request again.的内容