2011-04-25 76 views
1

我开始尝试使用Spring MVC,并注意到我的jsps作为html文件提供。例如。如何配置spring mvc/jsp来输出xhtml而不是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我与<html>标签JSP,所以我没有任何房间之前添加的文档类型。

回答

0

没有快速修复这个问题,基本上你必须重写你的jsps以符合html标准并添加相应的DOCTYPE。

您可以使用JSP生成几乎任何类型的文本文件。如果您制作CSV,XHTML,Quirks模式HTML或其他任何内容,JSP本身并不在意。

现在,如果您使用JSPX,那么您将受到一些限制,因为这些文件必须是有效的xml。

+0

请参阅我对@ nfechner的回答的评论 - 我不明白这是如何工作的。 – ripper234 2011-04-26 07:57:39

+0

Spring并没有添加这样的内容,有些地方在你的jsps中可以找到doc类型和html标签。 – 2011-04-26 14:20:07

1

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

+0

不是真的..这将打破..因为生成的代码将与XHTML不兼容。 – 2011-04-25 17:43:31

+0

对不起,但哪一部分不是真的?服务器(而不是客户端)不关心HTML?这个问题没有提到任何有关生成的代码。 – nfechner 2011-04-25 19:10:14

+0

对不起,如果评论不是很清楚......我应该提到的是“不够”。将jsp更改为xhtml是第一步如何使spring mvc与xhtml一起工作。由于一些代码宏现在将生成不符合标准的xhtml标记,因此验证问题会导致代码开始中断。 – 2011-04-25 19:18:55

0

以下是在web.xml中条目的网络流量,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> 

+0

有什么不同? – 2013-08-13 01:31:57

相关问题