Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Website loads correctly only after a refresh  RSS feed

 
Robert Insanovation White
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, my struggle is to find out why when I access the site for the first time, it loads a blank white page, but when I reload it, it forwards me to the home page as it should.

I doubt that the reason is nothing else than the code below (in the doGet method):



I suppose it's something with the session... because after I reload it, it works. But! When I close the browser and start all over again, the main page is white-blank again... And after a reload it works.

The exception:
SEVERE: Servlet.service() for servlet [first] in context with path [/MYSITE] threw exception
java.lang.NullPointerException
at controller.Controller.doGet(Controller.java:42)


Line 42 of the Controller is

P.S. I cleared all the cookies, but the problem persists.

Also, the first it loads, it prints in console:
"null
been here 4!"

But, if I reload further, it prints:
"null
been here 4!
been here 2!
No Email! Literally, doGet!"
 
Robert Insanovation White
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, I modified my code by checking if the array of cookies is Null. This solved the problem.

P.S. Nevertheless, thank you, coderanch! =D
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A couple of things. That line number refers to the code in the compiled version of the servlet, not the source code, so I suspect it was actually failing on this line:

You probably could have also fixed it by changing that line to this:

One more thing. This code is inefficient:

It would not be unusual for a system to have hundreds or possibly even thousands of cookies (depending on how much it's used and how well it's maintained). This code is going to have to calculate the length on every pass through the loop thus adding significant overhead. It can be improved a couple different ways.

Or more succinctly:

 
Robert Insanovation White
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
J. Kevin Robbins,

Great, thank's for the ideas, I used them immediately =)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!