开发者

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

开发者 https://www.devze.com 2023-03-01 02:35 出处:网络
I\'m starting to experiment with Spring MVC, and noticed that my jsps are served as html file开发者_运维百科s. E.g.

I'm starting to experiment with Spring MVC, and noticed that my jsps are served as html file开发者_运维百科s. 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.


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.


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.


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>

0

精彩评论

暂无评论...
验证码 换一张
取 消