• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

JSP document (complete post)

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 <jsp:output> action with the omit-xml-declaration set to "true" or "yes"

i.e <jsp:output omit-xml-declaration="true">
 
Sivasundaram Umapathy
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Can't .... do .... plaid .... So I did this tiny ad instead:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic