首页 \ 问答 \ 为什么在spring-boot velocity view 标签内没有解析“_csrf”属性?(Why is “_csrf” attribute not resolved inside spring-boot velocity view tags?)

为什么在spring-boot velocity view 标签内没有解析“_csrf”属性?(Why is “_csrf” attribute not resolved inside spring-boot velocity view tags?)

我有一个Spring-Boot项目,Velocity模板所有配置和工作正常...

在我的速度视图中,我有以下内容;

<head>
    <!-- some other meta tags here -->

    <meta name="csrf-token" content="$!_csrf.token">
</head>

这是我在检查chrome时输出的样子;

<meta name="csrf-token" content="$!_csrf.token">


然而,在同一页面上,我有一个看起来像这样的表格;

<form method="post" action="/post/to/wherever">
    <input type="hidden" id="csrf" name="$!_csrf.parameterName" value="$!_csrf.token" data-header="$!_csrf.headerName"/>

    <!-- other fields here -->

</form>

浏览器检查显示以下内容;

<input type="hidden" name="_csrf" value="69799b81-7c45-4042-9269-3a83769df682" data-header="X-CSRF-TOKEN">

很明显, _csrf属性在表单体内注入并解析,但不在元标记内。

问题:什么会导致这样的事情?


I have a Spring-Boot project with Velocity templating all configured and working fine...

In my velocity view, I have the following;

<head>
    <!-- some other meta tags here -->

    <meta name="csrf-token" content="$!_csrf.token">
</head>

Here's what the output looks like when I inspect in chrome;

<meta name="csrf-token" content="$!_csrf.token">


However on this same page I have a form that looks something like this;

<form method="post" action="/post/to/wherever">
    <input type="hidden" id="csrf" name="$!_csrf.parameterName" value="$!_csrf.token" data-header="$!_csrf.headerName"/>

    <!-- other fields here -->

</form>

And the browser inspection shows the following;

<input type="hidden" name="_csrf" value="69799b81-7c45-4042-9269-3a83769df682" data-header="X-CSRF-TOKEN">

So obviously, the _csrf attribute gets injected and resolved within the form body but not within the head meta tags.

QUESTION: What would cause a thing like this?


原文:https://stackoverflow.com/questions/38477200
更新时间:2024-01-01 11:01

最满意答案

试试localStorage

localStorage对象存储没有过期日期的数据。 当浏览器关闭时,数据不会被删除,并且将在第二天,一周或一年中可用。

index.html中,你可以替换你的

<a href="HelpFiles.html" class="readMore">Read more...</a>

<a href="HelpFiles.html?page=products" class="readMore">Read more...</a>

在此页面顶部添加此脚本

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $(".itemContent .readMore").click(function(){
        var imgName = $(this).parent().parent().find("img").attr("src");
        url = $(this).attr("href"); //Gets the url from the anchor tag clicked
        var page = url.split("?page=");
        localStorage.setItem("pageName", page[1]);
        localStorage.setItem("imageName", imgName);
    });
 });
</script>

在您的helpfiles.html中,您必须在顶部添加以下脚本

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
    $(document).ready(function(){
       var pageName = localStorage.getItem("pageName"); 
       var imagepath =localStorage.getItem("imageName");
       $("#helpFiles").load(pageName+".html"); 
});
</script>

希望这可能会给你一个想法伴侣.. :)

FYI

localStorage的

加载()


Try localStorage

The localStorage object stores the data with no expiration date. The data will not be deleted when the browser is closed, and will be available the next day, week, or year.

In your index.html you could replace your

<a href="HelpFiles.html" class="readMore">Read more...</a>

with

<a href="HelpFiles.html?page=products" class="readMore">Read more...</a>

Add this script on the top of this page

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $(".itemContent .readMore").click(function(){
        var imgName = $(this).parent().parent().find("img").attr("src");
        url = $(this).attr("href"); //Gets the url from the anchor tag clicked
        var page = url.split("?page=");
        localStorage.setItem("pageName", page[1]);
        localStorage.setItem("imageName", imgName);
    });
 });
</script>

In your helpfiles.html you have to add the following script on top

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
    $(document).ready(function(){
       var pageName = localStorage.getItem("pageName"); 
       var imagepath =localStorage.getItem("imageName");
       $("#helpFiles").load(pageName+".html"); 
});
</script>

Hope this might give you an idea mate.. :)

FYI

localStorage

load()

相关问答

更多
  • 试试localStorage localStorage对象存储没有过期日期的数据。 当浏览器关闭时,数据不会被删除,并且将在第二天,一周或一年中可用。 在index.html中,你可以替换你的 Read more...Read more... 在此页面顶部添加此脚本