Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP document (complete post)

 
Adri Smith
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have create a simple JSP document as following

<html xmlns:jsp="http://java.sun.com/JSP/Page">
<head>
<title>Hello World</title>
</head>
<body>
<jsp:scriptlet> out.println("Hello World !"); </jsp:scriptlet>
</body>
</html>

and I am surprised to see an XML document in my browser. as you can see the container is adding the line <?xml version="1.0"... ?> at the beginning of the document (during translation phase). That is why I am seeing the content of my XML file as below:

<?xml version="1.0" encoding="UTF-8" ?>
<html>
- <head>
<title>Hello World</title>
</head>
<body>Hello World !</body>
</html>

I expected the code HTML to be interpreted, but it is not. MY question is there a mean to make my HTML code interpreted ? If not this means we cannot make anything we can with conventionnal JSP syntax.

Finally I

Thanks for who will have the patience to answer my question.
Tiggy
 
Sivasundaram Umapathy
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The xml declaration can be avoided in 2 ways so that your document is considered as HTML.

1. By making use of <jsp:root> in your JSP document. In this case, the xml declaration is not added by default.

2. Using the <jsputput> action with the omit-xml-declaration set to "true" or "yes"

i.e <jsputput omit-xml-declaration="true">
 
Sivasundaram Umapathy
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tiggy tiggy, Can you please change your display name according to Javaranch naming policy ?
 
Adri Smith
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot

your response is very clear and brief, exactely what I expected

Tiggy
 
Adri Smith
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I changed my name as required

Have a nice day
 
Adri Smith
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a note. I have tested the code

<html xmlns:jsp="http://java.sun.com/JSP/Page">
<jsp utput omit-xml-declaration="true"/>

<head>
<title>A JSP document</title>
</head>
<body>
<jsp:scriptlet> out.println("Hello World !"); </jsp:scriptlet>
</body>
</html>

I still received this text in my browser but as forseen without the <?xml... declaration

<html>
- <head>
<title>A JSP document</title>
</head>
<body>Hello World !</body>
</html>

I checked on the class java generated and I see why it is like that. In fact I have the following line:

response.setContentType("text/xml;charset=UTF-8");

I guess this is because IE do not handle UTF8 yet.

Of course if we add the following directive this makes the things running right:

<jsp irective.page contentType="text/html"/>

That was just for your information.

Adri
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic