struts22 theme主题标签

 view plaincopy to clipboardprint?

<table align="center">   
<tr>  
   <td>  
       <s:textfield label="%{getText('username')}" name="username" size="20" cssClass="input01" theme="simple"/>  
   </td>  
</tr>  
<tr>  
   <td>  
       <s:textfield label="%{getText('userpass')}" name="userpass"  size="20" cssClass="input01"/>  
   </td>  
</tr>  
</table>   
 
 
这样的话,struts2框架会自动生成label以及一些提示信息,生成的html代码如下:
 
 
view plaincopy to clipboardprint?
<table align="center">  
<tr>  
    <td>  
       <input type="text" name="username" size="20" value="" id="_username" class="input01"/>  
    </td>  
</tr>  
<tr>  
    <td>  
       <tr>  
         <td class="tdLabel"><label for="_userpass" class="label">密码:</label></td>  
         <td>  
            <input type="text" name="userpass" size="20" value="" id="_userpass" class="input01"/>  
         </td>  
      </tr>  
    </td>  
</tr>  
</table>  
 
 我们会发现有生成许多代价,有些时候还会生成错误提示信息的代码,可我不想要它啊,我想把它放到别的地方去,或者干脆说,我只想用Struts的action处理机制,不想用struts的默认布局,又或者你想做。。。。。。总之就不要默认的,怎么办?
 
这就涉及到struts2的theme(主题)了,换不同的主题,可以让struts的代码输出不同的html代码,
 
问题一:Struts2有哪些主题?
 
Struts2提供了三种主题,ajax, simple, xhtml,它默认的是xhtml主题,当然你可以写任意个你自己的主题,我们称之为自定义主题
 
问题二:Struts2怎么改?
 
比如现在你想用simple主题,在Struts.xml中,加上下一行代码就可以了
 
<constant name="struts.ui.theme" value="simple" />
 
或者:在你的struts.propertise内加入以下: 
struts.ui.theme=simple
 
struts2—from标签中 theme="simple" 用法
 
在struts-core-2.06.jar中包含了一些默认的模版文件($ {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" />
 
---
demo:
----
<s:form action="Login"> 
    <table align="center"> 
      <tr> 
          <td> <s:textfield name="username" label="名 称"/> </td> 
        </tr> 
        <tr> 
          <td> <s:textfield name="password" label="密 码"/> </td> 
        </tr> 
        <tr> 
          <td> 
            <s:submit value="登录"  /> <s:reset value="重填" /> 
          </td> 
        </tr> 
    </table> 
  </s:form> 
在页面上显示就变成两行显示,而且右对齐,难道默认就是这样? 
 
 
解释:仔细看你生成的html代码,会发现多了很多多余的tr,td等,因为struts2表单标签本来就会自动生成的 
你又再次添加,就多余了,
 
下面这段代码可行的:
 
HTML code 
 
    <s:form action="Login"> 
        <table align="center"> 
             <s:textfield name="username" label="名 称"/> 
             <s:textfield name="password" label="密 码"/> 
                 <tr> 
                      <td colspan="2" align="center"> 
                           <s:submit value="login" theme="simple" /> 
                           <s:reset value="reset" theme = "simple"/> 
                      </td> 
                 </tr> 
        </table> 
    </s:form> 
 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值