如何避免在Struts中生成更多HTML元素 [英] How to avoid generating more HTML elements in Struts

查看:105
本文介绍了如何避免在Struts中生成更多HTML元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Struts(2)的UI标记时,会自动生成更多HTML元素.例如,在定义<s:form ... >时,它会将form包含在table中(即使我们未声明该表) .因此,如果使用任何CSS(可以说,仅使用div标签并根据CSS定位输入元素),由于自动生成的元素及其位置,所有元素均无法按预期方式查看.即使允许Struts生成此类元素,并且我们向其中添加CSS,也必须增加另一个负担来添加CSS来设计自动生成的html元素,因为会在不同的位置和大小下生成更多的元素.同样,我认为,更多的html代码可能会影响浏览器页面的加载时间.

When Struts(2)' UI tags are used, more HTML elements are generated automatically.For example, when defining <s:form ... > it includes form within a table(even though such table is not declared by us). So, if any CSS is used(lets say, a div tag is only used and located input elements according to the CSS), all elements are not viewed as expected because of auto generated elements and their postions. Even if the struts is allowed to generate such elements and we add CSS to them, then another weight must be bored to add css to design auto generated html elements because more elements are generated in various positions and sizes. Also as I feel, more html codes may effect the browser page loading time.

因此,有一种方法可以避免在使用struts UI标记时生成此类元素.
或其他
有没有在Struts UI标记中使用CSS的便捷方法? (我在Stackoverflow中读了一个问题,它的答案是,最后添加struts生成的css.但是与普通的jsp html设计级别相比,这并不容易.)

So is there a way to avoid generating such elements when struts UI tags are used
OR ELSE
is there a convenient way to work with CSS in Struts UI tags ? (I read a question in Stackoverflow and it had said for an answer that, to add css finally which the struts generated. But it is not that much easy when compare to normal jsp html designing level..)

推荐答案

简而言之,Struts2致力于主题概念的开发,并提供了某些现成的主题.根据所选主题,渲染视图时,它将为使用的标签生成一些HTML代码.

In short Struts2 work on the concept of themes and it provides certain theme out of the box. Based on the theme selected it will generate some HTML code for the used tags when rendering the view.

主题确实非常漂亮Struts2的概念,甚至可以根据您的要求为您提供创建自定义主题的方法.

Themes are really a very nice and beautiful concept of Struts2 and it even provides you the way to create a custom themes are per your requirement.

默认情况下,Struts2使用xhtml主题来问您的问题,这意味着它将在渲染所用标记的HTML时生成一些HTML(其中包括建议的表格).

coming to your Question by default Struts2 use xhtml theme which means it will generate some HTML (which includes tables as name suggested) while rendering the HTML for the used tags.

您可以通过在struts.properties文件或struts.xml文件中指定简单主题来控制HTML生成

you can control the HTML generation by specifying simple theme either in struts.properties file or in struts.xml file

struts.ui.theme=simple

Struts.xml文件

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

S2提供的其他主题是

Other theme being provided by S2 out of the box are

  • css_xhtml:生成基于div的HTML
  • ajax:用于ajax标签

请注意,简单主题不会生成任何额外的HTML,而只会标记等效的HTML代码,并且您可以通过提供自己的CSS和任何其他属性来完全控制自定义视图.

Note that simple theme will not generate any extra HTML but only tags equivalent HTML code and you have full control to customize ur view by providing your own CSS and any other properties.

属性文件以及struts.xml中的上述设置将适用于整个应用程序,这意味着每个标签将为整个应用程序生成相同的HTML.此外,如果您想控制每个标签HTML的生成,则将每个S2标签作为属性,即theme,为该属性提供值,例如simple,css_xhtml等,以控制每个标记HTML的生成.

Above settings in properties file as well in struts.xml will be applicable to entire application which means each and every tag will generate same HTML for whole appllication.beside that if you want to control per tag HTML generation each S2 tag as a property namely theme, provide value to this property like simple,css_xhtml etc to control per tag HTML generation.

还有另一种方法,可以使用以下代码来控制每个请求的主题 > 或

There is one more way to control the theme per request basis by using the following code <s:set name="theme" value="'simple'" scope="page" /> or

<s:set name="theme" value="%{myTheme}" scope="page" />

选择哪种方式都是您想走的

Choice is all yours which way you want to go

这篇关于如何避免在Struts中生成更多HTML元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆