ripper234
ripper234

Reputation: 229988

How can I configure spring mvc/jsp to output xhtml instead of html?

I'm starting to experiment with Spring MVC, and noticed that my jsps are served as html files. E.g.

<html>
<head>
...

</html>

How can I configure Spring MVC to serve xhtml files instead?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
...
</html>

Note - SpringMVC prefixes my jsp with the <html> tag, so I don't have any room to add the doctype before that.

Upvotes: 1

Views: 2543

Answers (3)

Saurabh
Saurabh

Reputation: 629

Following is entry in web.xml for web flow , jsf and xhtml display:

    <bean id="jpaFlowExecutionListener" class="org.springframework.webflow.persistence.JpaFlowExecutionListener">
            <constructor-arg ref="entityManagerFactory" />
            <constructor-arg ref="transactionManager" />
    </bean>

<bean id="facesContextListener" class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener" />

<webflow:flow-executor id="flowExecutor">
    <webflow:flow-execution-listeners>
        <webflow:listener ref="jpaFlowExecutionListener"/>
        <webflow:listener ref="facesContextListener"/>
    </webflow:flow-execution-listeners>
</webflow:flow-executor>

<webflow:flow-registry id="flowRegistry" flow-builder-services="facesFlowBuilderServices" base-path="/WEB-INF/flows">
    <webflow:flow-location-pattern value="/**/*-flow.xml"/> 
</webflow:flow-registry>

<faces:flow-builder-services id="facesFlowBuilderServices" development="true" />

<faces:resources/>

<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
    <property name="order" value="1"/>
    <property name="flowRegistry" ref="flowRegistry"/>
    <property name="defaultHandler">
         <bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
    </property> 
</bean>

<bean class="org.springframework.faces.webflow.JsfFlowHandlerAdapter">
    <property name="flowExecutor" ref="flowExecutor" />
</bean>

<bean id="faceletsViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.faces.mvc.JsfView"/>
    <property name ="prefix" value="/WEB-INF/" />
    <property name="suffix" value=".xhtml" />
</bean>

<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"></bean>

Upvotes: 0

nfechner
nfechner

Reputation: 17525

Change your JSPs. To the server, all HTML is just text. But beware, that you need to change more than the doctype. You will also have to check the JSPs (and also included files, etc) that they conform to the new standard. e.g. closing tags, lower-case tag and attribute names.

Upvotes: 1

Karthik Ramachandran
Karthik Ramachandran

Reputation: 12175

There is no quick fix to this one, basically you have to rewrite your jsps to be html compliant and add the appropriate DOCTYPE.

You can use JSPs to produce pretty much any type of text file. JSP itself doesn't care if you are making a CSV, XHTML, Quirks mode HTML, or anything else.

Now if your using JSPX you are a little more limited in that those files have to be valid xml.

Upvotes: 0

Related Questions