struts入门之return type(二)

 上次简单的看了看struts的 return  type   如果你想看看的话,在这里

 

今天接着看看另外剩下的几个type。到现在为止我还没有用过那些,所有也没有什么经验可谈。不过还是要了解下撒。以后用到的时候只是还知道有个这样的东西可以用撒。

 

 

Stream

这个是一个自定义的返回类型,通过InputStream用来直接发送数据到HttpServletResponse。对于允许用户下载东西的功能来说非常有用。

 

参数:

 

contentType :要发送到浏览器的mime-type  ,默认text/plain

 

contentLength :stream的长度 (单位是:byte)。这样浏览器就可以显示进度条了。

 

contentDispostion :给具体的文件名内容部署 header值 (默认 inline , 值通常是像这样:filename="document.pdf" )(原文:the content disposition header value for specifing the file name (default = inline , values are typically filename="document.pdf" .)

 

inputName :InputStream连接( chained )到action的属性的名字。默认就是 InputStream

 

bufferSize : 输入输出的缓冲区大小。默认:1024。

 

例子:

 

 

Velocity

 

用于 Velocity模版引擎的。感觉和 FreeMarker差不多。

 

 

location (default) :模版的位置。

 

parse :默认TRUE,如果设置FALSE的话,the location param will not be parsed for Ognl expressions。^_^

 

注:This result follows the same rules from StrutsResultSupport.(这个原滋原味)

 

 

 


XSL

 

这个返回类型使用 XSLT 把一个action对象转化为 XML.(强大)

 

参数:

location (default) :模版的位置,不要跟上面的搞混了。

 

parse :同上,默认TRUE。

 

matchingPattern :匹配模式,默认只是匹配想要的元素,但是默认,匹配所有元素。

 

excludingPatter: 不包括的元素。和上面是相反的,就是消除不需要的元素,默认一个都不匹配。

 

另注:

struts.properties related configuration:

  • struts.xslt.nocache - Defaults to false. If set to true, disables stylesheet caching. Good for development, bad for production.

struts.properties 有相关的配置可以设置。

 

一个小例子:

 

官方文档的例子,我对这个不太熟。

 

 

 

PlainText

 

这个是 按照 原文 (plain text) 来发送内容的,比如说你想显示  jsp 或者 HTML里面的原始数据的时候。

 

location (default): 要显示的网页文件的位置。

 

charSet (可选):    如果使用了就设置了 response 的类型 (eg. Content-Type=text/plain; charset=UTF-8)

 

小小例子,不成意思:

 

 

 

 

Tiles

 

注:Tiles is a templating framework designed to easily allow the creation of web application pages with a consistent look and feel. It can be used for both page decorating and componentization.自己翻译了下,虽然自己看懂了,但翻译后反而失去了原来的味道。还是看原文吧。

 

 

要使用  有4步:

 

1.Include the struts-tiles-plugin as a dependency in your web application. If you are using maven2, the dependency configuration will be similar to:

 

如:

 

2.Register the tiles listener. This listener will typically either be the standard tiles listener (org.apache.tiles.listener.TilesListener) or the Struts2 replacement (org.apache.struts2.tiles.TilesListener). The latter provides tighter integration with Struts features such as freemarker integration.

 

如:

 

 

 

3.All package definitions which require tiles support must either extend the tiles-default package or must register the Tiles Result type definition.

 

如:

 

4.Configure your actions to utilize a tiles definition:

 

如:

 

 

接下来是个小例子:

This example shows a Tiles layout page using Struts tags:

这个例子展示了一个用了  struts  标签  tiles  布局页面。

 

 

一共就这么几个了,最后那个tiles  我还没有用过,具体是什么东西我也不知道。但是存在即有价值,不然struts的开发人员怎么会把这个加上。先记住有这么一个东西吧,说不定哪一天:“哦,原来这个是用来做这个的哦”。

 

 

我就是,这样的,是有些,小地方,不理解,怎么办,先记住,看以后,用到了,就明白。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值