JSP get data from another session when I switch to another jsp file












0















I have two jsp files login.jsp and index.jsp, login.jsp do an ajax call where after authentication are set values in session with setAttribute('key', value) then a javascript switch to a index.jsp using window.location.href='index.jsp'. index.jsp is calling getAttribute('key') to get the value but the value obtained is not de same which set in login.jsp.



this is the ajax call in login.jsp



 75         function login() {
76 var usuario = $("#usuario").val();
77 var password = $("#password").val();
78 var agente = navigator.userAgent;
79
80 $.post("app/bd.jsp", {
81 funcion: "login",
82 "usuario": usuario,
83 "password": password,
84 "agente": agente
85 }, function (data) {
86 if (data.trim() === "ok") {
87
88 window.location.href = 'index.jsp';
89 } else {
90 $(".has-usuario").addClass("has-error");
91 $(".has-password").addClass("has-error");
92 $("#mensaje-login").html("Usuario o password invalido");
93 }
94 });


After authentication validation, this is executed in bd.jsp when the ajax call is performed:



 287 session.setAttribute("clte_code_cliente", 
resultado.getString("usrw_clte_code_cliente"));
288 session.setAttribute("clte_nombre_razon", resultado.getString("clte_nombre_razon"));
289 session.setAttribute("usrw_usuario", resultado.getString("usrw_usuario"));
290 session.setAttribute("usrw_nombre", resultado.getString("usrw_nombre"));
291 session.setAttribute("usrw_tipo", resultado.getInt("usrw_tipo"));
292 session.setAttribute("usrw_id", resultado.getInt("usrw_id"));


Then window.location.href = 'index.jsp'; switch to index.jsp when the callback of the ajax call is executed.



Finally in the index.jsp I try to retrieve the session values as:



 488 <div class="col-sm-8">
489 <input type="text"
490 value="<%=session.getAttribute("clte_code_cliente")%>"
491 onblur="traerRazonSocial();" class="form-control" id="inputCodigo"
492 placeholder="Codigo de cliente" required autofocus disabled>
493 </div>


But the information which retrieves session.getAttribute() function is not the correct user information, that information belongs to another user logged before.



thanks!










share|improve this question

























  • please include code you've tried

    – ehacinom
    Nov 21 '18 at 21:37











  • I update it, thanks!

    – Ersualo
    Nov 21 '18 at 22:07











  • make sure your function that calls setAttribute is in the callback of the ajax call

    – ehacinom
    Nov 21 '18 at 22:14











  • if that doesn't help try console logging the session after you do session.setAttribute to make sure the session is actually what you expect. I don't know jsp but does the line value="<%=session.getAttribute("clte_code_cliente")%>" with double quotes " inside of another double quotes work or do you need to use single quotes?

    – ehacinom
    Nov 21 '18 at 22:14











  • It is in the callback and the answer is yes, It works in that way. This was working perfect but for two weeks it started to happen. I'm wondering if this is related to the browser or something on the client side, maybe cache.

    – Ersualo
    Nov 21 '18 at 22:20
















0















I have two jsp files login.jsp and index.jsp, login.jsp do an ajax call where after authentication are set values in session with setAttribute('key', value) then a javascript switch to a index.jsp using window.location.href='index.jsp'. index.jsp is calling getAttribute('key') to get the value but the value obtained is not de same which set in login.jsp.



this is the ajax call in login.jsp



 75         function login() {
76 var usuario = $("#usuario").val();
77 var password = $("#password").val();
78 var agente = navigator.userAgent;
79
80 $.post("app/bd.jsp", {
81 funcion: "login",
82 "usuario": usuario,
83 "password": password,
84 "agente": agente
85 }, function (data) {
86 if (data.trim() === "ok") {
87
88 window.location.href = 'index.jsp';
89 } else {
90 $(".has-usuario").addClass("has-error");
91 $(".has-password").addClass("has-error");
92 $("#mensaje-login").html("Usuario o password invalido");
93 }
94 });


After authentication validation, this is executed in bd.jsp when the ajax call is performed:



 287 session.setAttribute("clte_code_cliente", 
resultado.getString("usrw_clte_code_cliente"));
288 session.setAttribute("clte_nombre_razon", resultado.getString("clte_nombre_razon"));
289 session.setAttribute("usrw_usuario", resultado.getString("usrw_usuario"));
290 session.setAttribute("usrw_nombre", resultado.getString("usrw_nombre"));
291 session.setAttribute("usrw_tipo", resultado.getInt("usrw_tipo"));
292 session.setAttribute("usrw_id", resultado.getInt("usrw_id"));


Then window.location.href = 'index.jsp'; switch to index.jsp when the callback of the ajax call is executed.



Finally in the index.jsp I try to retrieve the session values as:



 488 <div class="col-sm-8">
489 <input type="text"
490 value="<%=session.getAttribute("clte_code_cliente")%>"
491 onblur="traerRazonSocial();" class="form-control" id="inputCodigo"
492 placeholder="Codigo de cliente" required autofocus disabled>
493 </div>


But the information which retrieves session.getAttribute() function is not the correct user information, that information belongs to another user logged before.



thanks!










share|improve this question

























  • please include code you've tried

    – ehacinom
    Nov 21 '18 at 21:37











  • I update it, thanks!

    – Ersualo
    Nov 21 '18 at 22:07











  • make sure your function that calls setAttribute is in the callback of the ajax call

    – ehacinom
    Nov 21 '18 at 22:14











  • if that doesn't help try console logging the session after you do session.setAttribute to make sure the session is actually what you expect. I don't know jsp but does the line value="<%=session.getAttribute("clte_code_cliente")%>" with double quotes " inside of another double quotes work or do you need to use single quotes?

    – ehacinom
    Nov 21 '18 at 22:14











  • It is in the callback and the answer is yes, It works in that way. This was working perfect but for two weeks it started to happen. I'm wondering if this is related to the browser or something on the client side, maybe cache.

    – Ersualo
    Nov 21 '18 at 22:20














0












0








0








I have two jsp files login.jsp and index.jsp, login.jsp do an ajax call where after authentication are set values in session with setAttribute('key', value) then a javascript switch to a index.jsp using window.location.href='index.jsp'. index.jsp is calling getAttribute('key') to get the value but the value obtained is not de same which set in login.jsp.



this is the ajax call in login.jsp



 75         function login() {
76 var usuario = $("#usuario").val();
77 var password = $("#password").val();
78 var agente = navigator.userAgent;
79
80 $.post("app/bd.jsp", {
81 funcion: "login",
82 "usuario": usuario,
83 "password": password,
84 "agente": agente
85 }, function (data) {
86 if (data.trim() === "ok") {
87
88 window.location.href = 'index.jsp';
89 } else {
90 $(".has-usuario").addClass("has-error");
91 $(".has-password").addClass("has-error");
92 $("#mensaje-login").html("Usuario o password invalido");
93 }
94 });


After authentication validation, this is executed in bd.jsp when the ajax call is performed:



 287 session.setAttribute("clte_code_cliente", 
resultado.getString("usrw_clte_code_cliente"));
288 session.setAttribute("clte_nombre_razon", resultado.getString("clte_nombre_razon"));
289 session.setAttribute("usrw_usuario", resultado.getString("usrw_usuario"));
290 session.setAttribute("usrw_nombre", resultado.getString("usrw_nombre"));
291 session.setAttribute("usrw_tipo", resultado.getInt("usrw_tipo"));
292 session.setAttribute("usrw_id", resultado.getInt("usrw_id"));


Then window.location.href = 'index.jsp'; switch to index.jsp when the callback of the ajax call is executed.



Finally in the index.jsp I try to retrieve the session values as:



 488 <div class="col-sm-8">
489 <input type="text"
490 value="<%=session.getAttribute("clte_code_cliente")%>"
491 onblur="traerRazonSocial();" class="form-control" id="inputCodigo"
492 placeholder="Codigo de cliente" required autofocus disabled>
493 </div>


But the information which retrieves session.getAttribute() function is not the correct user information, that information belongs to another user logged before.



thanks!










share|improve this question
















I have two jsp files login.jsp and index.jsp, login.jsp do an ajax call where after authentication are set values in session with setAttribute('key', value) then a javascript switch to a index.jsp using window.location.href='index.jsp'. index.jsp is calling getAttribute('key') to get the value but the value obtained is not de same which set in login.jsp.



this is the ajax call in login.jsp



 75         function login() {
76 var usuario = $("#usuario").val();
77 var password = $("#password").val();
78 var agente = navigator.userAgent;
79
80 $.post("app/bd.jsp", {
81 funcion: "login",
82 "usuario": usuario,
83 "password": password,
84 "agente": agente
85 }, function (data) {
86 if (data.trim() === "ok") {
87
88 window.location.href = 'index.jsp';
89 } else {
90 $(".has-usuario").addClass("has-error");
91 $(".has-password").addClass("has-error");
92 $("#mensaje-login").html("Usuario o password invalido");
93 }
94 });


After authentication validation, this is executed in bd.jsp when the ajax call is performed:



 287 session.setAttribute("clte_code_cliente", 
resultado.getString("usrw_clte_code_cliente"));
288 session.setAttribute("clte_nombre_razon", resultado.getString("clte_nombre_razon"));
289 session.setAttribute("usrw_usuario", resultado.getString("usrw_usuario"));
290 session.setAttribute("usrw_nombre", resultado.getString("usrw_nombre"));
291 session.setAttribute("usrw_tipo", resultado.getInt("usrw_tipo"));
292 session.setAttribute("usrw_id", resultado.getInt("usrw_id"));


Then window.location.href = 'index.jsp'; switch to index.jsp when the callback of the ajax call is executed.



Finally in the index.jsp I try to retrieve the session values as:



 488 <div class="col-sm-8">
489 <input type="text"
490 value="<%=session.getAttribute("clte_code_cliente")%>"
491 onblur="traerRazonSocial();" class="form-control" id="inputCodigo"
492 placeholder="Codigo de cliente" required autofocus disabled>
493 </div>


But the information which retrieves session.getAttribute() function is not the correct user information, that information belongs to another user logged before.



thanks!







javascript jsp session location href






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 22:07







Ersualo

















asked Nov 21 '18 at 21:19









ErsualoErsualo

12




12













  • please include code you've tried

    – ehacinom
    Nov 21 '18 at 21:37











  • I update it, thanks!

    – Ersualo
    Nov 21 '18 at 22:07











  • make sure your function that calls setAttribute is in the callback of the ajax call

    – ehacinom
    Nov 21 '18 at 22:14











  • if that doesn't help try console logging the session after you do session.setAttribute to make sure the session is actually what you expect. I don't know jsp but does the line value="<%=session.getAttribute("clte_code_cliente")%>" with double quotes " inside of another double quotes work or do you need to use single quotes?

    – ehacinom
    Nov 21 '18 at 22:14











  • It is in the callback and the answer is yes, It works in that way. This was working perfect but for two weeks it started to happen. I'm wondering if this is related to the browser or something on the client side, maybe cache.

    – Ersualo
    Nov 21 '18 at 22:20



















  • please include code you've tried

    – ehacinom
    Nov 21 '18 at 21:37











  • I update it, thanks!

    – Ersualo
    Nov 21 '18 at 22:07











  • make sure your function that calls setAttribute is in the callback of the ajax call

    – ehacinom
    Nov 21 '18 at 22:14











  • if that doesn't help try console logging the session after you do session.setAttribute to make sure the session is actually what you expect. I don't know jsp but does the line value="<%=session.getAttribute("clte_code_cliente")%>" with double quotes " inside of another double quotes work or do you need to use single quotes?

    – ehacinom
    Nov 21 '18 at 22:14











  • It is in the callback and the answer is yes, It works in that way. This was working perfect but for two weeks it started to happen. I'm wondering if this is related to the browser or something on the client side, maybe cache.

    – Ersualo
    Nov 21 '18 at 22:20

















please include code you've tried

– ehacinom
Nov 21 '18 at 21:37





please include code you've tried

– ehacinom
Nov 21 '18 at 21:37













I update it, thanks!

– Ersualo
Nov 21 '18 at 22:07





I update it, thanks!

– Ersualo
Nov 21 '18 at 22:07













make sure your function that calls setAttribute is in the callback of the ajax call

– ehacinom
Nov 21 '18 at 22:14





make sure your function that calls setAttribute is in the callback of the ajax call

– ehacinom
Nov 21 '18 at 22:14













if that doesn't help try console logging the session after you do session.setAttribute to make sure the session is actually what you expect. I don't know jsp but does the line value="<%=session.getAttribute("clte_code_cliente")%>" with double quotes " inside of another double quotes work or do you need to use single quotes?

– ehacinom
Nov 21 '18 at 22:14





if that doesn't help try console logging the session after you do session.setAttribute to make sure the session is actually what you expect. I don't know jsp but does the line value="<%=session.getAttribute("clte_code_cliente")%>" with double quotes " inside of another double quotes work or do you need to use single quotes?

– ehacinom
Nov 21 '18 at 22:14













It is in the callback and the answer is yes, It works in that way. This was working perfect but for two weeks it started to happen. I'm wondering if this is related to the browser or something on the client side, maybe cache.

– Ersualo
Nov 21 '18 at 22:20





It is in the callback and the answer is yes, It works in that way. This was working perfect but for two weeks it started to happen. I'm wondering if this is related to the browser or something on the client side, maybe cache.

– Ersualo
Nov 21 '18 at 22:20












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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420612%2fjsp-get-data-from-another-session-when-i-switch-to-another-jsp-file%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
















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420612%2fjsp-get-data-from-another-session-when-i-switch-to-another-jsp-file%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen