Issue
i am a newbie in ember and servlet. Here is the code snippet of dashboard.js from the route directory.
import Route from '@ember/routing/route';
export default class DashboardRoute extends Route {
async model()
{
let response = await fetch("http://localhost:8080/Servlet/getfilename");
let data = await response.json();
return data;
}
}
I have maintained Session in my Servlet (i.e) When an user logged in via login Page LoginServlet will create a Session for the request and redirects the user to the Dashboard Page, where it fetches a json response from another servlet which does a session validation. Now that throws an error saying that the Session is null.Why does this happen? Is there is way to store the Session ID in ember and send it to the servlet via fetch?
Thanks in advance
Solution
I think you'll want to look over these docs from MDN: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
potentially, adding this to your fetch request's options:
credentials: 'same-origin',
more information on credentials can be found here: https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials
Answered By - NullVoxPopuli
Answer Checked By - Senaida (JavaFixing Volunteer)