Creating session after sending response to client Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Create ArrayList from arrayHow can I create an executable JAR with dependencies using Maven?How do I create a file and write to it in Java?Creating a memory leak with JavaDownload Excel File by sending ajax requestdoes process still continue after client disconnectsHow to get session when request is completedHow to render partial view in Spring MVCgetting null value in the controller while submitting the formhow to take utf -8 characters from html form in spring controller characters like pi symbol , integration symbol
Does the transliteration of 'Dravidian' exist in Hindu scripture? Does 'Dravida' refer to a Geographical area or an ethnic group?
Can gravitational waves pass through a black hole?
How to resize main filesystem
Is there a verb for listening stealthily?
Understanding piped commands in GNU/Linux
Twin's vs. Twins'
The Nth Gryphon Number
How do I say "this must not happen"?
An isoperimetric-type inequality inside a cube
How could a hydrazine and N2O4 cloud (or it's reactants) show up in weather radar?
Why does BitLocker not use RSA?
Is there a spell that can create a permanent fire?
Weaponising the Grasp-at-a-Distance spell
Vertical ranges of Column Plots in 12
Is this Half-dragon Quaggoth boss monster balanced?
Should man-made satellites feature an intelligent inverted "cow catcher"?
Did pre-Columbian Americans know the spherical shape of the Earth?
What are some likely causes to domain member PC losing contact to domain controller?
How to ask rejected full-time candidates to apply to teach individual courses?
First paper to introduce the "principal-agent problem"
As a dual citizen, my US passport will expire one day after traveling to the US. Will this work?
How to make triangles with rounded sides and corners? (squircle with 3 sides)
Russian equivalents of おしゃれは足元から (Every good outfit starts with the shoes)
Noise in Eigenvalues plot
Creating session after sending response to client
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Create ArrayList from arrayHow can I create an executable JAR with dependencies using Maven?How do I create a file and write to it in Java?Creating a memory leak with JavaDownload Excel File by sending ajax requestdoes process still continue after client disconnectsHow to get session when request is completedHow to render partial view in Spring MVCgetting null value in the controller while submitting the formhow to take utf -8 characters from html form in spring controller characters like pi symbol , integration symbol
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am trying to execute a method(which takes a long time for execution) immediately after sending response from controller without having to keep the client wait for response.
My source code for sending the response is as follows,
@RequestMapping(value = "exportExcelReportService", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void exportExcelReportServiceGetJsonObject(@ModelAttribute ReqParam reqParam, HttpServletResponse response)
java.io.PrintWriter wr;
try
wr = response.getWriter();
response.setStatus(HttpServletResponse.SC_OK);
wr.print(response);
wr.flush();
wr.close();
exportDataUsingVMService.getByteArrayForExcelSheet(reqParam);
catch (IOException e)
// TODO Auto-generated catch block
e.printStackTrace();
Over here getByteArrayForExcelSheet will get executed after the response has been sent to client. But I'm unable to create session in this method,
public void getByteArrayForExcelSheet(ReqParam reqParam)
JSONObject jObject = null;
HttpSession httpsession = request.getSession(false);
Where request is autowired like this,
@Autowired
private HttpServletRequest request;
I get exception in getByteArrayForExcelSheet
like this,
java.lang.IllegalStateException: Cannot create a session after the response has been committed
java spring spring-mvc
add a comment |
I am trying to execute a method(which takes a long time for execution) immediately after sending response from controller without having to keep the client wait for response.
My source code for sending the response is as follows,
@RequestMapping(value = "exportExcelReportService", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void exportExcelReportServiceGetJsonObject(@ModelAttribute ReqParam reqParam, HttpServletResponse response)
java.io.PrintWriter wr;
try
wr = response.getWriter();
response.setStatus(HttpServletResponse.SC_OK);
wr.print(response);
wr.flush();
wr.close();
exportDataUsingVMService.getByteArrayForExcelSheet(reqParam);
catch (IOException e)
// TODO Auto-generated catch block
e.printStackTrace();
Over here getByteArrayForExcelSheet will get executed after the response has been sent to client. But I'm unable to create session in this method,
public void getByteArrayForExcelSheet(ReqParam reqParam)
JSONObject jObject = null;
HttpSession httpsession = request.getSession(false);
Where request is autowired like this,
@Autowired
private HttpServletRequest request;
I get exception in getByteArrayForExcelSheet
like this,
java.lang.IllegalStateException: Cannot create a session after the response has been committed
java spring spring-mvc
2
Create the session before you send the response; the session requires a cookie; and the cookie must be sent as a header. Thus you must create the session first (but you can pass it to your method).
– Elliott Frisch
Mar 22 at 12:42
Thank you very much @ElliottFrisch, I attached the httpsession to reqParam before sending the response, like this, reqParam.setHttpsession(request.getSession()); then I used it in my getByteArrayForExcelSheet method.
– AJN
Mar 22 at 12:58
add a comment |
I am trying to execute a method(which takes a long time for execution) immediately after sending response from controller without having to keep the client wait for response.
My source code for sending the response is as follows,
@RequestMapping(value = "exportExcelReportService", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void exportExcelReportServiceGetJsonObject(@ModelAttribute ReqParam reqParam, HttpServletResponse response)
java.io.PrintWriter wr;
try
wr = response.getWriter();
response.setStatus(HttpServletResponse.SC_OK);
wr.print(response);
wr.flush();
wr.close();
exportDataUsingVMService.getByteArrayForExcelSheet(reqParam);
catch (IOException e)
// TODO Auto-generated catch block
e.printStackTrace();
Over here getByteArrayForExcelSheet will get executed after the response has been sent to client. But I'm unable to create session in this method,
public void getByteArrayForExcelSheet(ReqParam reqParam)
JSONObject jObject = null;
HttpSession httpsession = request.getSession(false);
Where request is autowired like this,
@Autowired
private HttpServletRequest request;
I get exception in getByteArrayForExcelSheet
like this,
java.lang.IllegalStateException: Cannot create a session after the response has been committed
java spring spring-mvc
I am trying to execute a method(which takes a long time for execution) immediately after sending response from controller without having to keep the client wait for response.
My source code for sending the response is as follows,
@RequestMapping(value = "exportExcelReportService", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void exportExcelReportServiceGetJsonObject(@ModelAttribute ReqParam reqParam, HttpServletResponse response)
java.io.PrintWriter wr;
try
wr = response.getWriter();
response.setStatus(HttpServletResponse.SC_OK);
wr.print(response);
wr.flush();
wr.close();
exportDataUsingVMService.getByteArrayForExcelSheet(reqParam);
catch (IOException e)
// TODO Auto-generated catch block
e.printStackTrace();
Over here getByteArrayForExcelSheet will get executed after the response has been sent to client. But I'm unable to create session in this method,
public void getByteArrayForExcelSheet(ReqParam reqParam)
JSONObject jObject = null;
HttpSession httpsession = request.getSession(false);
Where request is autowired like this,
@Autowired
private HttpServletRequest request;
I get exception in getByteArrayForExcelSheet
like this,
java.lang.IllegalStateException: Cannot create a session after the response has been committed
java spring spring-mvc
java spring spring-mvc
edited Mar 22 at 12:49
vs97
1,2581322
1,2581322
asked Mar 22 at 12:39
AJNAJN
11611
11611
2
Create the session before you send the response; the session requires a cookie; and the cookie must be sent as a header. Thus you must create the session first (but you can pass it to your method).
– Elliott Frisch
Mar 22 at 12:42
Thank you very much @ElliottFrisch, I attached the httpsession to reqParam before sending the response, like this, reqParam.setHttpsession(request.getSession()); then I used it in my getByteArrayForExcelSheet method.
– AJN
Mar 22 at 12:58
add a comment |
2
Create the session before you send the response; the session requires a cookie; and the cookie must be sent as a header. Thus you must create the session first (but you can pass it to your method).
– Elliott Frisch
Mar 22 at 12:42
Thank you very much @ElliottFrisch, I attached the httpsession to reqParam before sending the response, like this, reqParam.setHttpsession(request.getSession()); then I used it in my getByteArrayForExcelSheet method.
– AJN
Mar 22 at 12:58
2
2
Create the session before you send the response; the session requires a cookie; and the cookie must be sent as a header. Thus you must create the session first (but you can pass it to your method).
– Elliott Frisch
Mar 22 at 12:42
Create the session before you send the response; the session requires a cookie; and the cookie must be sent as a header. Thus you must create the session first (but you can pass it to your method).
– Elliott Frisch
Mar 22 at 12:42
Thank you very much @ElliottFrisch, I attached the httpsession to reqParam before sending the response, like this, reqParam.setHttpsession(request.getSession()); then I used it in my getByteArrayForExcelSheet method.
– AJN
Mar 22 at 12:58
Thank you very much @ElliottFrisch, I attached the httpsession to reqParam before sending the response, like this, reqParam.setHttpsession(request.getSession()); then I used it in my getByteArrayForExcelSheet method.
– AJN
Mar 22 at 12:58
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55299810%2fcreating-session-after-sending-response-to-client%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55299810%2fcreating-session-after-sending-response-to-client%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Create the session before you send the response; the session requires a cookie; and the cookie must be sent as a header. Thus you must create the session first (but you can pass it to your method).
– Elliott Frisch
Mar 22 at 12:42
Thank you very much @ElliottFrisch, I attached the httpsession to reqParam before sending the response, like this, reqParam.setHttpsession(request.getSession()); then I used it in my getByteArrayForExcelSheet method.
– AJN
Mar 22 at 12:58