I have been studying for JPA and struggled with a bug which made me very confused and later I have found out that it was Chrome caused the program run incorrectly.
I recently switched from Firefox to Chrome. And when I use glassfish admin console in Chrome, whenever after I deployed the app and try to open http://<mymachinename>:8080/myapp/runservlet, I found out the servlet (I don't include code here as it is not specific but generally every servlet dealing with JPA and javadb) will be called TWICE.
Normally if behave correctly, after persisted a entity and auto generate ID, I should get one entity in the database. However, I always get another duplicate in the database. For example, I have a employee named John Smith and I should have a row in Employee table with auto-gen'ed ID 1 and John Smith, but instead somehow, I got ID 1/John Smith and ID 2/John Smith.
At first I thought it was a bug in my code and I tried for a long time to find out but no success. Then I tried same code in IE, the same code behaves correctly no matter how many times I try!
And I tried to run different code and I found it is a general problem not the specific program which I found the problem first with.
Then I found out more:
If I open the app in Chrome at the following address the problem will be gone:
Do anyone know why app running by Chrome is behaved this way and how to fix it?
I would need to sit down myself and check this Paul. I can't say from the other side of the globe. Yes, different browers do behave differently for different scripting languages. I am not sure though that the problem that you describe is related to the browser. It could be or there could be a different reason to it. These type of issues need a lot of hit and trial, careful observation and experience to home in on. For now , I suggest you continue with FireFox or IE.
Google Chrome has "Developer Tools" which you can use to track the requests being sent to the server. It will also show you the HTTP response code and such. On the server side I think you can enable "access logs" - I don't know how it's done in GlassFish. Those access logs should ideally show you the requests to the server and the response codes. Either or both of these should probably give you an hint on what's going on. In fact, you could even compare the server side access logs with IE and Chrome and see if there's any difference.
Yes Jai. There would certainly be a plugin or a built in tool to monitor requests made. That would be of great help. Just check this portal Paul. It just might help. Install this and monitor the requests like Jai suggested.
Joined: Apr 25, 2013
I will continue to try the suggested.
But there is a little progress: I found the request header from Chrome and IE are different by one line, in Chrome there is "Cache-Control: max-age=0" but not in IE. And if I config setting to disable cache in Chrome developer tools, everything works fine.
Paul.J Wong wrote:I found the request header from Chrome and IE are different by one line, in Chrome there is "Cache-Control: max-age=0" but not in IE. And if I config setting to disable cache in Chrome developer tools, everything works fine.
From your question, the servlet is hit twice per request. I don't understand how cache-control affects the first request. If Chrome is making one request to render the page and another to cache it, then that would be a bug.
Let me post codes, they are fairly simple. Two entities, one stateless bean and one servlet. In Chrome only, from line 14 and 15 of the servlet everything works, but when hit line 17 to 20, there will be 8 PrintJobs records in the database so basically every line of 17 to 20 caused a printjob entities persisted twice.
Joined: Apr 25, 2013
Mansukhdeep Thind wrote:That explains it Paul. Cache-Control max-age setting instructs the client about whether it should re-validate every request again or pick it up from the cache as per the max age setting. Read this.
I have Chrome in all its default settings, and I disabled all extensions.
But I found that from line 14 and 15 of the servlet above everything works but 17 to 20 cause entities to persisted twice, those two portion of codes belong to same doGet method.
subject: Google chrome, glassfish local server and servlet being called twice