在用Struts2开发一些界面时,经常需要用到其标签,如果需要我们自己以Table的形式来排版的话,则Struts2的标签也会自己生成一些html语言,比如<s:textfield/>会自己生成一个<TD/>样的html,这样页面就造成了混乱,后来查找了下资料,在struts-core-2.16.jar的包中包含了一些默认的模版文件,它们位于$ {struts-core-2.16.jar}/template下,其中有ajax,simple,xhtml等。
查看一下struts.properties,如果没有可以查看$ {struts-core-2.06.jar}/org/apache/struts2/default.properties文件,其中有如下配置:
struts.ui.theme=xhtml
struts.ui.templateDir=template
struts.ui.templateSuffix=ftl
这一段就是关于struts2模版的配置信息,我们可以修改struts.properties文件,将其改成
struts.ui.theme=simple
struts.ui.templateDir=template
struts.ui.templateSuffix=ftl
也可以修改struts.xml文件,在其中加入如下行
<constant name="struts.ui.theme" value="simple" />
<constant name="struts.ui.templateDir" value="template" />
<constant name="struts.ui.templateSuffix" value="ftl" />
这样,<s:textfield/>这样的标签就不会自动生成html了.
还有一个解决的办法就是在<s:form/>中设置theme属性,变为theme=“simple”,就可以解决,不过对于整个项目来说,配置全局的就可以了,没有必要每个页面都设置一下theme属性