2013-07-04 117 views
-1

我有一個Java EE應用程序,它使用Velocity來顯示HTML頁面。我的問題是重定向頁面或在我的java方法ConfigurationF3Controller()完成執行後刷新頁面,應將哪些參數傳遞給我的veloCity對象,以便在我的方法完成後重新加載相同的頁面?如何在java方法執行完成後刷新頁面

下面的代碼是速度模板片段:

<link rel="stylesheet" type="text/css" href="color.css"> 
<link rel="stylesheet" type="text/css" href="layout.css"> 

<div id="conteneur" class="import-woalis"> 
    <div class="info-title"> 
     <span class="portefeuille"><u> Fichier de configuration F3</u></span> 
    </div> 

    <div id="content"> 
     <div class="descriptif-contrat"> 
      <table cellspacing="10" border="0"> 
       <tr> 
        <td colspan="2"> 
         <span class="libelle" style="width: 130px">Configuartion File<br />file type F3</span> 
         <form action="fichier-configuration-f3.html?action=importerFichierConfiguration" method="post" enctype="multipart/form-data" name="importerFichierConfForm"> 
          <input type="file" name="file" size="50" id="check" /> 
         </form>  
        </td> 
       </tr> 
       <tr> 
        <td> 
         <span class="libelle" style="color: red;"><u>Attention :</u><br>file mist be of UNIX type</span> 
        </td> 
        <td valign="top"> 
         <div class="button-box"><input type="button" class="button button-import" onclick="document.importerFichierConfForm.submit();"></div> 
        </td> 
       </tr> 
       <tr> 
        <td colspan="2"> 
         <span class="libelle">actual file contents : </span> 
        </td> 
       </tr> 
       <tr> 
        <td colspan="2"> 
         <textarea cols="90%" rows="25" readonly="true" style="resize: none" >$fileControllerF3</textarea> 
        </td> 
       </tr> 
      </table> 
     </div> 
    </div> 
</div> 

的第二代碼片段是加載起始頁,並用文件的Unix服務器上的內容填充它。

public class ConfigurationF3Controller extends MainController { 

    public ModelAndView begin(final HttpServletRequest pRequest, final HttpServletResponse pResponse) throws Exception { 
     final Context vContext = getContext(pRequest, pResponse); 

     if (null == vContext) { 
      return null; 
     } 

     final VelocityContext vVelocityContext = new VelocityContext(); 

     final String vNomdePage = "administration/fichier-configuration-f3.vm"; 

     // file fileF3 will contain the path and the file name on the server Constantes.PARAM_IMPORT_FICHIER_F3 
     final String vRepertoireF3 = ParamDelegator.getParameter(Constantes.PARAM_IMPORT_FICHIER_F3); 
     final File fileF3 = new File(vRepertoireF3 + Constantes.NAME_FILE_CONFIG_F3); 

     // call for a method which uses Buffered reader to read the file on the server   
     String fileControllerF3 = getFileConfigurationF3(fileF3); 

     // call for velocity to put the contents of the read file in the html field called fileControllerF3(see first part of the code) 
     vVelocityContext.put("fileControllerF3", fileControllerF3); 

     affichePage(vNomdePage, vContext, pRequest, pResponse, vVelocityContext, Constantes.EC_ADM_FICHIER_CONFIG_F3); 

     return null; 
    } 

    //Another Method to display nothing on the page! 
    public ModelAndView affichePagePrincp(final HttpServletRequest pReq, final HttpServletResponse pResponse) 
      throws Exception { 

     final Context vContext = getContext(pReq, pResponse); 

     if (null == vContext) { 
      return null; 
     } 

     final VelocityContext vVelocityContext = new VelocityContext(); 
     final String vNomdePage = "administration/fichier-configuration-f3.vm"; 
     final String stringBlank = ""; 

     vVelocityContext.put("fileControllerF3", stringBlank); 

     affichePage(vNomdePage, vContext, pReq, pResponse, vVelocityContext, Constantes.EC_ADM_FICHIER_CONFIG_F3); 

     return null; 
    } 
} 
+0

你在這裏問2個無關的問題。請編輯您的問題,以便它只是其中一個問題 – Edd

+0

確定已更改它。現在有答案嗎? –

回答

1

java方法結束後沒有必要刷新頁面。

當您執行上一個servlet的HTTP GET請求,你會普遍預期的HTTP響應包含頁面內容

所以,你需要做的就是渲染速度模板,並將其連接到響應什麼

+0

@Baturay如果這不明確,那麼請包含'affichePage()'的代碼,因爲它看起來像這是魔術應該發生的地方 – Edd

相關問題