2017-10-05 7 views
0

vue.jsコードを持つスプリングブートアプリケーションを開発中です。Springブートでindex.htmlにクッキーまたはヘッダーを設定する方法

初期コンテキスト "/"では、index.htmlページにCookieまたはヘッダーを設定します。

私は次のコードを試しましたが、私は404を得続けています。これを修正する方法に関するアイデアはありますか?

@Controller 
public class TestController { 

@RequestMapping(path = "/", method = RequestMethod.GET) 
public String index(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) 
     throws IOException { 

    String reqUrl = httpServletRequest.getRequestURL().toString(); 
    String displayName = httpServletRequest.getHeader("displayName"); 

    if (StringUtils.isBlank(displayName)) { 

     String url = "http://example.com/sso/?targetUrl=" + reqUrl; 

     URL obj = new URL(url); 

     HttpURLConnection con = (HttpURLConnection) obj.openConnection(); 
     con.setRequestMethod("POST"); 
     System.out.println("Header from SSO" + con.getHeaderField("displayName")); 
     httpServletResponse.setHeader("displayName", con.getHeaderField("displayName")); 
    } 

    return "index"; 
} 

} 

これは私のプロジェクト構造の様子です。

Project Structure of Spring Boot App

答えて

0

私は私が

return "index.html"; 
に私のreturn文を変更しなければならなかった私の問題を考え出しました
0

あなたがちょうど作成したのHttpURLConnectionからヘッダを取得しようとしているように見えますか?

あなたはHttpClientを使用の方がよいでしょう「」http://example.com/sso」URLにリレーしようとしている場合。

関連する問題