从 Thymeleaf 模板重定向页面 [英] Redirecting page from Thymeleaf template

查看:70
本文介绍了从 Thymeleaf 模板重定向页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 Thymeleaf 重定向页面(我有如下 JSP 代码)

How to redirect the page from Thymeleaf (I have JSP code like below)

out.println("REDIRECT=http://www.example.com/api/response?id="+id)

Thymeleaf 中的等价物是什么?我想从模板中做到这一点.

What is the equivalent in Thymeleaf? I want to do it from the template.

推荐答案

Thymeleaf 不提供任何从其模板重定向到另一个页面的机制——我也不建议这样做(因为这是这可能应该在控制器级别处理).

Thymeleaf doesn't provide any mechanism for redirecting to another page from one of its templates -- and I wouldn't recommend doing it anyways (since this is something that should probably be handled at the controller level).

话虽如此,可以使用 javascript 来做到这一点.像这样:

That being said, it's possible to do this using javascript. Something like this:

<script th:inline="javascript">
    window.location.href = 'http://www.example.com/api/response?id=' + [[${id}]];
</script>

或者可能是元刷新标签.

Or possibly the meta refresh tag.

<meta http-equiv="refresh" th:attr="content=${'5; url=http://example.com/api/response?id=' + id}" />

这篇关于从 Thymeleaf 模板重定向页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆