我有一个 Java EE 应用程序,它使用 Velocity 来显示 HTML 页面。我的问题是在我的 java 方法 ConfigurationF3Controller() 完成执行后重定向页面或刷新页面,我应该将哪些参数传递给我的 veloCity 对象,以便它在我的方法完成后重新加载同一页面?
下面的代码是速度模板片段:
<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;
}
}