deadend
deadend

Reputation: 1376

Java IE Gives Old HTTP Servlet Session Object

I am using IE 11 for my application. i am facing session issue here.

When doing first transaction, in transaction response jsp page i get current transaction no say 1000 [(TransactionDO) session.getAttribute("txnDetails");]. In same jsp i did ng-init="GetTxnResponse()" in div, from that js function getting transaction no as 1000.

then i am doing second transaction with the same session without logout, in transaction response jsp page i get current transaction no as 1001 from http session. In same jsp from ng-init="GetTxnResponse()" js function getting transaction no as 1000 instead of 1001.

Its occurs only in IE. Please help to resolve. Below is my code for reference.

-- JSP Code --

<fmt:setLocale value='en_US' />
<%
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); 
// HTTP 1.1.
response.setHeader("Pragma","no-cache"); //HTTP 1.0 
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server

TransactionDO txnDO = (TransactionDO) session.getAttribute("txnDetails");
System.out.println("Txn no : "+txnDO.txnNo()); // Here i get 1001 second time

%>

<fmt:bundle basename="applicationresources">
    <div ng-controller="txnController"
        ng-init="GetTxnResponse()" >
        ---
        --- 
    </div>
</fmt:bundle>

-- JS Code --

    self.GetTxnResponse = function() {
    if (txnStatus == '00') {
        $http.get(CONTEXT_PATH + '/getResponseDetails').success(function(data) {
        // Here i get 1000 from data second time
        }
    }   

-- Java Code --

    @RequestMapping(value="/getResponseDetails", method=RequestMethod.GET)
    public @ResponseBody TransactionDO getResponseDetails(HttpServletRequest httpRequest){
    TransactionDO txnDO = null;
        txnDO = (TransactionDO) httpRequest.getSession().getAttribute("txnDetails");        
        return txnDO;
    }

Upvotes: 0

Views: 45

Answers (1)

Joop Eggen
Joop Eggen

Reputation: 109613

Make the page stateless. That is solid practice. It also allows caching on the production site.

<div ng-controller="txnController"
    ng-init="GetTxnResponse(${txnDetails.txnNo})" >

self.GetTxnResponse = function(txnNo) {
    if (txnStatus == '00') {
        $http.get(CONTEXT_PATH + '/getResponseDetails/' + txnNo).success(function(data) {
        // Here i get 1000 from data second time

@RequestMapping(value="/getResponseDetails/{txnNo}", method=RequestMethod.GET)
public @ResponseBody TransactionDO getResponseDetails(HttpServletRequest httpRequest,
        @PathVariable long txnNo) {
    ...
}

You need probably to adapt the page a bit more than the code shown.

To explain it a bit more: the user could open two tabs with the same page, and then play around. Guess what?

Upvotes: 1

Related Questions