---
title: "Struts2 的四种theme类型"
author: "newleague"
date: "2010-10-29T10:13:16Z"
tags: ["Ajax", "CSS", "HTML", "XHTML"]
categories: ["企业架构"]
slug: "struts2-theme"
draft: false
lastmod: "2011-08-03T16:35:23Z"
id: 797312
url: "https://newleague.iteye.com/blog/797312"
---

struts2 中有四种 theme 类型：

simple theme A minimal theme with no "bells and whistles"

xhtml theme The default theme that uses common HTML practices

css\_xhtml theme The xhtml theme re-implemented using strictly CSS for layout

ajax theme A theme based on the xhtml theme that provides advanced AJAX features

除了simple theme之外，其他的theme都会自动为你生成layout，例如

&lt;s:form&gt;

&lt;s:submint /&gt;

&lt;/s:form&gt;

会生成如下的HTML片段：

&lt;form&gt;

&lt;table&gt;

&lt;tr&gt;

&lt;td&gt;&lt;input type="submit" ../&gt;

&lt;/tr&gt;

&lt;/table&gt;

&lt;/form&gt;

所以如果使用这三种类型的theme不需要使用table定layout。

如果使用simple的theme才需要使用table定layout。

但是按照你的想法，使用前三种theme无法把submit和reset放在同一个tr中（即无法放在同一行）

解决方法：

1 使用simple theme ， 但是这样子的话你无法使用ajax的一些特性，需要自己编写ajax的特性。

2 基于xhtml theme自己重新写一个theme，但是难度会大一点。

 

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**

**struts.xml:**

 &lt;constant name="struts.ui.theme" value="css\_xhtml" /&gt;

jsp:

&lt;s:form namespace="/admin/category" id="deleteCarSeriesForm" action="deleteCarSeries" method="post"  theme="launch"&gt;