如何在java方法完成执行后刷新页面

时间:2013-07-04 20:15:35

标签: java java-ee velocity

我有一个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;
    }
}

1 个答案:

答案 0 :(得分:1)

在java方法完成后无需刷新页面。

当您在servlet上执行http GET请求时,您通常希望http响应包含页面内容

所以你需要做的是渲染速度模板并将其附加到响应