【问题标题】:XSRF token mismatchXSRF 令牌不匹配
【发布时间】:2019-01-26 07:10:02
【问题描述】:

您好,我正在尝试通过管理部分中的自定义控制器处理表单提交

这是我的测试控制器

@Controller
@RequestMapping("/" + TempController.SECTION_KEY)
public class TempController extends AdminAbstractController {
    protected static final String SECTION_KEY = "test2";

    @RequestMapping(value = "", method = RequestMethod.GET)
    public String test(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
        // This is expected by the modules/emptyContainer template, this is a custom template that gets included into the body
        model.addAttribute("customView", "views/test2");
        ShippingEntity shp=new ShippingEntity();
        model.addAttribute("shipping",shp);
        // ensure navigation gets set up correctly
        setModelAttributes(model, SECTION_KEY);

        // gets the scaffolding set up to display the template from the customView attribute above
        return "modules/emptyContainer";
    }

    @RequestMapping(value = "", method = RequestMethod.POST)
    public String testPost(HttpServletRequest request, HttpServletResponse response, Model model,@ModelAttribute ShippingEntity shp) throws Exception {
        // This is expected by the modules/emptyContainer template, this is a custom template that gets included into the body
        model.addAttribute("customView", "views/test2");
        System.out.println(shp.getLink());
        System.out.println(shp.getTrackingNumber());
        model.addAttribute("shipping",shp);
        // ensure navigation gets set up correctly
        setModelAttributes(model, SECTION_KEY);

        // gets the scaffolding set up to display the template from the customView attribute above
        return "modules/emptyContainer";
    }


}   

这是视图模板:

<div class="row">
    <div class="twelve columns">
           <form action="#" th:action="@{/test2}" th:object="${shipping}" method="post">
        <p>Id: <input type="text" th:field="*{trackingNumber}" /></p>
        <p>Message: <input type="text" th:field="*{link}" /></p>
        <p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
    </form>

    </div>
</div>

问题是当我提交值时出现错误:

XSRF 令牌不匹配(空)。会话可能已过期

我知道这与安全问题有关,但是我找不到使它起作用的方法。

任何提示如何解决这个问题?

【问题讨论】:

    标签: broadleaf-commerce


    【解决方案1】:

    显然它比我想象的要简单,也许它会在未来帮助某人。

    只需将&lt;form&gt; &lt;/form&gt; 更改为&lt;blc:form&gt;&lt;/blc:form&gt;

    【讨论】:

      猜你喜欢
      • 2020-11-09
      • 2021-04-07
      • 1970-01-01
      • 1970-01-01
      • 2020-10-29
      • 1970-01-01
      • 1970-01-01
      • 2016-11-16
      • 2016-10-07
      相关资源
      最近更新 更多