2012-07-12 79 views
1

正在寫包含一個按鈕,一個jsp頁面,我把代碼中的scriptlet執行是刷新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> 

任何想法可以理解 謝謝

回答

0

我覺得FORM方法是GET。你應該做的Form方法POST

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

GET是冪等要求,它可以讓瀏覽器上的刷新自動做出請求。然而,

POST是不冪等它可以讓瀏覽器顯示彈出詢問類似Do you want to submit the request again.

+0

但我不使用servlet – 2012-07-12 07:58:49

+0

我沒有得到你。你可以在你的jsp中發佈「 2012-07-12 08:01:19

+0

謝謝heree的表單標籤

2012-07-12 08:03:46