• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP page occasionally shows the HTML code instead of a formed web pag

 
Ray-Shine Chiu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I use Chrome browser to visit a JSP page running on Tomcat, most of time the JSPpage works well.
However, the JSP page occasionally shows the HTML code instead of a formed web page.
And, there are some strange codes, for example 1az, before <html> tag and after </html>.
After reload the JSP page, it shows a formed web page again.
Sometimes the encoding of the page is incorrect.
After reload the JSP page, it shows the page with correct encoding.
Does anyone know the reason why?
Thanks!
 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have had all kinds of problems with chrome, not only with java applications but also with php, ruby, .NET etc. while those apps always worked fine with firefox, IE, etc.

Even last week I had such a problem. The user re-installed Chrome and everything worked fine. I use mod_security and the logs showed that that user was sending all kinds of malformed requests to the server.

Anyway, it seems that Chrome has problems identifying the content type sent by your server. If your server sent content type text/plain than any browser should display the html source instead of rendered HTML.

1) Try to reproduce with other browsers
2) Try re-installing chrome
 
Ray-Shine Chiu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Côté for your help.

Anything wrong with the following codes?

<%@ page contentType="text/html;charset=utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ page import="java.util.*,java.text.DateFormat,java.text.SimpleDateFormat,javax.sql.*,java.sql.*" %>
<html>
<head>
<meta charset="UTF-8">
<title>...</title>
...
</head>
<body>
...
</body>
</html>
 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No you set text/html

Have you tried steps 1 and 2 I suggested in my previous post?

well here is what I use in a working application. Notice the semi-colon and the space instead of a colon in your post although I don't know if it makes a difference:



Try step 1 and 2 if that doesn't change anything...
 
Ray-Shine Chiu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Côté again for your help.

I modified the code from <%@ page contentType="text/html;charset=utf-8" %> to <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>.
The problem is still the same.
Occasionally it shows HTML code as the following:

2000
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<!--???-->
...
</body>
</html>
0

Each time the code before the <html> tag is different.
After reload the page it shows rendered page.

It seems rarely happened in IE.

I will try to reinstall chrome.
 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might have to debug the output of your server if it happens also in IE. Have you tried firefox?

At this point, you have to make sure if it is a Chrome issue or not. Try with other browsers and make sure you can reproduce.

Here is how the raw headers output from your server should actually look like:

You should make sure the headers returned by your server match the ones in your jsp files.



Yep, my server seems to automagically set the http headers to match the ones in the jsp.

Make sure yours do the same.
 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ray-Shine Chiu wrote:
2000
<html>

Each time the code before the <html> tag is different.
After reload the page it shows rendered page.

I will try to reinstall chrome.


Hmmm,,, not sure yet but it might be a server problem if it happens with all browsers.

Which server are you using?

My guess is that the "different codes" you are seeing every time is actually a byte length often used in keep-alive or more likely in chunked-encoding transfers.

https://en.wikipedia.org/wiki/Chunked_transfer_encoding

Your server might be at fault after all.



 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a quick fix, you may try disabling chunked-encoding, then keep-alives on your server.

Disabling chunked-encoding shouldn't hurt performance as much as disabling keep-alives but keep-alives don't send byte length anyway.
 
Ray-Shine Chiu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JSP container is Tomcat.

When the JSP code is executed first time, browser (not chrome only) shows the web page with incorrect encoding sometimes.
After that, the browser shows the web page with correct encoding.

And occasionally, chrome shows HTML code instead of rendered page.
When the page reloads every two minutes, it may work correctly for several hours.
However, it could show HTML code and stop reloading several hours later.
The HTML code shown is correct. It shouldn't be a problem while rendering.
I try to visit the page in several computers, the problem exists the same.
I am not sure whether the problem occurs on chrome only.
It's hardly to reproduce the problem on IE.

I don't know how to disable chunked-encoding and keep-alives on the server.

Thanks a lot!
 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which version of tomcat are you using?

Maybe upgrade/re-install your server.

http://tomcat.10.x6.nabble.com/Tomcat-and-quot-Chunked-Transfer-Encoding-quot-td5011939.html

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!