java - For some reason JSP documents output XML instead of HTML -
ok, trying set simple jsf application. i'm using netbeans 6.8, glassfishv3 , maven2. made jsp document so:
<?xml version="1.0" encoding="utf-8"?> <html xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"> <f:view> <head> <title><h:outputtext value="#{welcome.title}"/></title> </head> <body> <h:outputtext value="welcome"/> </body> </f:view> </html>
problem is, if navigate page (http://myhost/myapp/faces/welcome.jspx
), returned xml document, ${welcome.title}
value populated:
<?xml version="1.0" encoding="utf-8"?> <html><head><title>gymix - welcome</title></head><body>welcome</body></html>
in internet explorer looks have opened xml document. in google chrome title printed next text welcome , instead of title url page printed on tab.
if change jsp document plain jsp page (taglibs instead of xmlns , on) works , proper page returned. ideas on what's wrong? thanks!
edit: sadly none of quick fixes fixed this, i'll more. btw, pom.xml has jsf-api , jsf-impl dependencies version both set 1.2_14
aside fact need set proper doctype , content type browser knows page, should rid of old fashioned jspx
format , use xhtml
format benefit of java ee 6-shipped jsf 2.0 , facelets.
the given code should changed to:
<?xml version="1.0" encoding="utf-8"?> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"> <h:head> <title>#{welcome.title}</title> </h:head> <h:body> welcome </h:body> </html>
note doctype included , jsf 2.0 / facelets automatically take care right content type of <h:head>
component. note absence of <f:view>
tag, isn't needed anymore in facelets.
you need reconfigure webapp make use of full powers of jsf 2.0 , facelets. learn more jsf 2.0 , facelets, recommend go through java ee 6 tutorial part ii chapters 4-9.
good luck.
update: per comment of bobince: add important note; true xml declaration (the first line) mess rendering mode of webbrowsers (also see site behind doctype link here above), that's not issue here. facelets removes xml declaration during generating html of page. xml declaration there because facelets needs parse page using xml based tool first. we're talking component based mvc framework , xml based templating technology, not plain vanilla html page ;)
Comments
Post a Comment