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

发布于 2024-11-03 03:44:58 字数 455 浏览 1 评论 0原文

我开始尝试 Spring MVC,并注意到我的 jsps 作为 html 文件提供。例如,

<html>
<head>
...

</html>

我如何配置 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>

注意 - SpringMVC 在我的 jsp 中添加 标记作为前缀,因此我没有任何空间在此之前添加文档类型。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

渔村楼浪 2024-11-10 03:44:58

更改您的 JSP。对于服务器来说,所有 HTML 都只是文本。
但请注意,您需要更改的不仅仅是文档类型。您还必须检查 JSP(以及包含的文件等)是否符合新标准。例如结束标签、小写标签和属性名称。

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.

静水深流 2024-11-10 03:44:58

对此没有快速修复方法,基本上您必须重写 jsps 以使其兼容 html 并添加适当的 DOCTYPE。

您可以使用 JSP 生成几乎任何类型的文本文件。 JSP 本身并不关心您是否正在制作 CSV、XHTML、Quirks 模式 HTML 或其他任何内容。

现在,如果您使用 JSPX,您会受到更多限制,因为这些文件必须是有效的 xml。

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.

浮萍、无处依 2024-11-10 03:44:58

以下是 web.xml 中用于 web flow、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>

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>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文