2013-07-04 55 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

相关问题