user1504484
user1504484

Reputation: 1

Trying to maintain session in all the pages in Java

When a direct visitor comes to our site, we are unable to maintain cookies and session. For example, when visitor comes to our site for the first time, we get a null pointer exception. This is not happening when there is a return visitor to our site. Any idea why this could be happening?

Each page has a body tag. On loading the body tag, we don't get session values. We are getting only a null pointer exception (this is happening for a first time visitor only). When the same visitor comes back to our site, we are not getting a null pointer exception, and it seems to work fine.

body bgcolor="#778899" onload="change(),zipValid('<%=session.getAttribute("zip").toString() %>')"

I am trying to do this on the site www.unocardealers.com . Basically, whenever a visitor comes back to our site, we are trying to pre-fill the zip code field with the zip code they last searched with. If they are searching during the same session, then we are trying to pre-fill the zip code with which they searched previously.

Upvotes: 0

Views: 130

Answers (1)

ControlAltDel
ControlAltDel

Reputation: 35096


'<%=session.getAttribute("zip").toString() %>'

You are going to get a nullPointerException here if either session is null or session.getAttribute("zip") is null. Just add some null checking

Upvotes: 1

Related Questions