Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 向Spring重定向属性消息添加HTML链接_Java_Spring_Spring Mvc_Flash Message_Spring Messaging - Fatal编程技术网

Java 向Spring重定向属性消息添加HTML链接

Java 向Spring重定向属性消息添加HTML链接,java,spring,spring-mvc,flash-message,spring-messaging,Java,Spring,Spring Mvc,Flash Message,Spring Messaging,我们希望在最终用户在我们的网站上成功提交表单后,向信息性消息Spring RedictAttribute/Flash消息添加一个html可单击链接 因此,终端将看到以下flash消息: <%@tag body-content="empty"%> <%@ include file="/WEB-INF/views/html/common/include.jsp" %> <%@ attribute name="message" required="true" type="

我们希望在最终用户在我们的网站上成功提交表单后,向信息性消息Spring RedictAttribute/Flash消息添加一个html可单击链接

因此,终端将看到以下flash消息:

<%@tag body-content="empty"%>
<%@ include file="/WEB-INF/views/html/common/include.jsp" %>
<%@ attribute name="message" required="true" type="java.lang.String" %>

<c:if test="${not empty message}">
    <div class="info_message">
        <div class="title">Information:</div> 
        <div class="body">
            ${message}
        </div>
    </div>
</c:if>
成功

对象已更新

信息

记住

其中“编辑”属性将是最终用户浏览器中的可单击链接

我们很难协调的是,代码在哪里创建链接html文本

我们觉得messages.properties文件中不应该有任何html,控制器中也不应该有任何html生成

这是我们的控制器代码:

public ModelAndView processSubmit(@Valid ObjectCommand command, BindingResult bindingResult, RedirectAttributes redirectAttributes, HttpServletRequest request) {
    if (bindingResult.hasErrors()) {
        return new ModelAndView("/form.html");
    } else {
        // Command Object successfully send to service to update database as needed.

        // First Flash Message (the success message from above).
        redirectAttributes.addFlashAttribute("successMessage", "Object updated.");

        // Second Flash Message (The informational message from above urging the user to go update something else too.
        String informationMessage = this.getInformationMessage(request, object);
        redirectAttributes.addFlashAttribute("infoMessage", informationMessage);

        return new ModelAndView("redirect:/object.html");
    }
}

private String getInformationMessage(Request request, Object object) {
     // THIS CODE HERE, FEELS SLIMY.
     String editUrl = "Remember to <a href=\"" + request.getContextPath() + "/object/" + object.getIdentifier() + "/attribute.html\" />Edit Attribute</a>";
}
下面是显示这两条信息消息的jsp标记代码:

<%@tag body-content="empty"%>
<%@ include file="/WEB-INF/views/html/common/include.jsp" %>
<%@ attribute name="message" required="true" type="java.lang.String" %>

<c:if test="${not empty message}">
    <div class="info_message">
        <div class="title">Information:</div> 
        <div class="body">
            ${message}
        </div>
    </div>
</c:if>
任何关于如何在我们的信息信息中获得可点击链接的友好建议都将不胜感激

processSubmit需要返回重定向:/some url或重定向视图

在重定向属性中输入的值应在模型参数中可用,或在重定向后通过@modeldattributes可用

过程:

获取表单url=/formA,method=GET 用户发布的表单url=/formA,method=POST -保存/处理表单数据。设置重定向属性
-请说,/formA或/formcomplete

谢谢您的回复。我更新了代码以获得正确的重定向。但这真的不是我的问题。我的问题涉及getInformationMessage方法中的代码。在控制器中格式化html文本似乎是不对的,因为至少在我看来,控制器应该不知道它的视图实际上如何显示任何内容。这是我问题的症结所在。