首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Spring MVC使用POST重定向

Spring MVC使用POST重定向
EN

Stack Overflow用户
提问于 2020-09-20 01:37:59
回答 2查看 94关注 0票数 0
代码语言:javascript
运行
复制
I am trying to redirect a user to external url to complete the transaction and this website is based SAML based authentication and accepts SAMLResponse as a post parameter. Below is my controller able to get the values in the logs

-控制器-

代码语言:javascript
运行
复制
@RequestMapping(value="/redirect", method = { RequestMethod.GET, RequestMethod.POST })
       
public String redirect(HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttrs) {
    
  String samlRes =  String.valueOf(request.getSession().getAttribute("STRRESPONSE"));
    
  byte[] base64samlRes = Base64.encode(samlRes.getBytes());
    
           
  redirectAttrs.addAttribute("SAMLResponse", base64samlRes);
  L.debug("Redirecting " +  samlRes);
  L.debug("Redirecting  Base64 Encoder  " +    new String(base64samlRes, Charset.forName("UTF-8")));
  return "redirect";

-控制器结束

代码语言:javascript
运行
复制
and using the below html to post the external website.. I am seeing the browser the html title but it is not loading the external portal and values in the html is also null

- HTML自动提交

代码语言:javascript
运行
复制
  <!DOCTYPE html>
    <html xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Redirect Payment Portal</title>
    </head>
    <body>
    <ul>
        <li>SamlResponse: "${SAMLResponse}"</li>
    </ul>
    <form name="myRedirectForm" action="<external url>" method="post">
        <input name="SAMLResponse" type="hidden" value="${SAMLResponse}" />
        <noscript>
            <input type="submit" value="Click here to continue" />
        </noscript>
    </form>
    <script type="text/javascript">
    
            $(document).ready(function() {
                document.myRedirectForm.submit();
            });
    
        </script>
    </body>
    </html>

=====================结束超文本标记语言

我错过了什么吗?

EN

回答 2

Stack Overflow用户

发布于 2020-09-20 12:18:45

我可以通过修改值[${SAMLResponse}]来检索html格式的值,但是表单没有被提交

票数 0
EN

Stack Overflow用户

发布于 2020-09-21 05:12:32

最后,通过以下更新解决了这个问题

-HTML-修改以下行

代码语言:javascript
运行
复制
<input name="SAMLResponse" type="hidden" value="${SAMLResponse}" />

to

 <input name="SAMLResponse" type="hidden" th:value="${SAMLResponse}" />

-结束HTML

-控制器更改

代码语言:javascript
运行
复制
@RequestMapping(value="/redirect", method = { RequestMethod.GET, RequestMethod.POST })
       
public ModelAndView redirect(HttpServletRequest request, HttpServletResponse response, Model model) {
    
  String samlRes =  String.valueOf(request.getSession().getAttribute("STRRESPONSE"));
    
  byte[] base64samlRes = Base64.encode(samlRes.getBytes());
    
           
  model.addAttribute("SAMLResponse", new String(base64samlRes, Charset.forName("UTF-8"));
  L.debug("Redirecting " +  samlRes);
  L.debug("Redirecting  Base64 Encoder  " +    new String(base64samlRes, Charset.forName("UTF-8")));
  return new ModelAndView ("redirect");

-控制器更改结束

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63971641

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档