去除 struts2 标签中的自动生成的布局样式table/tr/td

使用struts2的时候发现如果按照默认的方式使用ui标签,会自动加上<tr><td>标签,比如:

<s:textfield key="username"/>

会显示成

<tr class=“xxx”><td><input type=text name=username/></td></tr>  

<tr class=“xxx”><td><input type=text name=username/></td></tr>

有时候并不需要这些td tr,所以可以这样写

 

<s:textfield key="username" theme="simple"/

<s:textfield key="username" theme="simple"/>

或者:修改struts2的配置文件

 

struts2中包含了一些默认的模版文件($ {struts-core-2.06.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.properties文件,可以修改struts.xml文件,在其中加入如下行

<constant name="struts.ui.theme" value="simple" />

<constant name="struts.ui.templateDir" value="template" />

<constant name="struts.ui.templateSuffix" value="ftl" />

struts.ui.theme=simple可以解决struts2标签自动换行问题,即不再自动被添加进table标签中。

猜你喜欢

转载自87029274.iteye.com/blog/1458484