简体   繁体   English

如何配置spring mvc / jsp以输出xhtml而不是html?

[英]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. 我开始尝试使用Spring MVC,并注意到我的jsps用作html文件。 Eg 例如

<html>
<head>
...

</html>

How can I configure Spring MVC to serve xhtml files instead? 如何配置Spring MVC来代替xhtml文件?

<!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. 注意 -SpringMVC在我的jsp前面加上<html>标记,因此在此之前我没有空间添加doctype。

Change your JSPs. 更改您的JSP。 To the server, all HTML is just text. 对于服务器而言,所有HTML都只是文本。 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. 您还必须检查JSP(以及包含的文件等)它们是否符合新标准。 eg closing tags, lower-case tag and attribute names. 例如,结束标记,小写标记和属性名称。

Following is entry in web.xml for web flow , jsf and xhtml display: 以下是web.xml中用于web流,jsf和xhtml显示的条目:

    <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>

There is no quick fix to this one, basically you have to rewrite your jsps to be html compliant and add the appropriate DOCTYPE. 对此没有快速解决方案,基本上,您必须重写jsps以使其符合html并添加适当的DOCTYPE。

You can use JSPs to produce pretty much any type of text file. 您可以使用JSP生成几乎任何类型的文本文件。 JSP itself doesn't care if you are making a CSV, XHTML, Quirks mode HTML, or anything else. JSP本身并不关心您是制作CSV,XHTML,Quirks模式的HTML还是其他任何东西。

Now if your using JSPX you are a little more limited in that those files have to be valid xml. 现在,如果您使用的是JSPX,您将受到更多限制,因为这些文件必须是有效的xml。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM