Struts1.x系列教程(6):Bean标签库

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="ProgId" content="Word.Document"> <meta name="Generator" content="Microsoft Word 11"> <meta name="Originator" content="Microsoft Word 11"> <link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml"> <!--[if gte mso 9]><xml> Normal 0 7.8 磅 0 2 false false false MicrosoftInternetExplorer4 </xml><![endif]--><!--[if gte mso 9]><![endif]--><style> <!-- /* Font Definitions */ &#64;font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1;} &#64;font-face {font-family:""&#64;宋体"; panose-1:2 1 6 0 3 1 1 1 1 1;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; font-size:10.5pt; font-family:"Times New Roman";} /* Page Definitions */ &#64;page {} &#64;page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt;} div.Section1 {page:Section1;} /* List Definitions */ &#64;list l0 {} &#64;list l0:level1 { margin-left:39.75pt; text-indent:-18.0pt;} &#64;list l0:level4 { margin-left:105.75pt; text-indent:-21.0pt;} ol {margin-bottom:0cm;} ul {margin-bottom:0cm;} --> </style> <!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable { mso-style-parent:""; font-size:10.0pt; font-family:"Times New Roman";} </style> <![endif]--> 本文为原创,如需转载,请注明作者和出处,谢谢!


《Struts 2系列教程》


上一篇:Struts1.x系列教程(5):HTML标签库

Bean标签库共有11个标签。这些标签可以完成如下五种工作:

1. 获得HTTP请求信息

2. 访问Java对象

3. 访问JSP内嵌对象和Struts配置对象

4. 访问Web资源和属性文件

5. 输出信息

下面我们就来分别介绍一下如何使用Bean标签库中的标签来完成上述的工作。

一、获得HTTP请求信息


使用Bean标签库中的标签可以访问Cookie、HTTP请求头以及请求参数。

1. <bean:cookie>标签

<bean:cookie>标签用于获得一个Cookie对象,并创建一个page范围的变量来保存这个Cookie对象。<bean:cookie>标签有三个常用属性:

(1)id:用于保存Cookie对象的变量名。

(2)name:Cookie名

(3)value:Cookie的默认值。如果name所指的Cookie不存在,<bean:cookie>标签就会创建一个新的Cookie对象,而value属性的值就是这个Cookie对象的value属性值。如果忽略value属性,当<bean:cookie>标签未找到name指写的Cookie时,就会抛出一个javax.servlet.jsp.JspException异常。因此,笔者建议在使用这个标签时加上value属性。

2. <bean:header>标签

<bean:header>标签用于获得HTTP请求头字段的值,并创建一个page范围的变量来保存请求头字段的值。<bean:header>标签有三个常用属性:

(1)id:用于保存HTTP请求头字段值的变量名。

(2)name:HTTP请求头字段名。

(3)value:HTTP请求头字段的默认值。如果name所指的HTTP请求头字段不存在,<bean:header>标签就会将value属性的值存在page范围的变量中。如果不指定value属性,且指定的HTTP请求头字段不存在时,<bean:header>标签就会抛出javax.servlet.jsp.JspException异常。

3.<bean:parameter>标签

<bean:parameter>标签用于获得HTTP请求参数的值,并创建一个page范围的变量来保存所获得的HTTP请求参数的值。<bean:parameter>标签有三个常用属性:

(1)id:用于保存HTTP请求参数值的变量名。

(2)name:HTTP请求参数名。

(3)value:HTTP请求参数值的默认值。如果name所指的HTTP请求参数不存在,<bean:parameter >标签就会将value属性的值存在page范围的变量中。如果不指定value属性,且指定的HTTP请求参数不存在时,<bean:parameter>标签就会抛出javax.servlet.jsp.JspException异常。

下面的例子演示了如何使用本节所讲的三个Bean标签来获得HTTP请求信息,在<samples工程目录>中建立一个httpRequestInfo.jsp文件,代码如下:

<!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --> <% @pagepageEncoding = " GBK " %>
<% @tagliburi = " http://struts.apache.org/tags-bean " prefix = " bean " %>
< html >
< head >
< title > 获得HTTP请求信息 </ title >
</ head >
< body >
<% -- 测试bean:cookie标签 -- %>
< bean:cookie id ="myCookie" name ="name" value ="default" />
<%
if (myCookie.getValue().equals( " default " ))
{
Cookiecookie
= new Cookie( " name " , " newCookie " );
cookie.setMaxAge(
1000 );
response.addCookie(cookie);
}
%>
${myCookie.value}
<% -- 用EL输出myCookie的value属性值 -- %>
<%
// ${myCookie.value}相当于如下Java代码
Cookiecookie
= (Cookie)pageContext.getAttribute( " myCookie " );
out.println(cookie.getValue());
%> < br >
<% -- 测试bean:header标签 -- %>
< bean:header id ="userAgent" name ="user-agent" value ="unknown" />
${userAgent}
< br > <% -- 用EL输出userAgent的值 -- %>
<% -- 测试bean:parameter标签 -- %>
< bean:parameter id ="myCountry" name ="country" value ="unknown" />
${myCountry}
<% -- 用EL输出myCountry的值 -- %>
</ body >
</ html >

在IE中输入如下的URL来测试httpRequestInfo.jsp:

http://localhost:8080/samples/httpRequestInfo.jsp?country=China
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="ProgId" content="Word.Document"><meta name="Generator" content="Microsoft Word 11"><meta name="Originator" content="Microsoft Word 11"><link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml"><!--[if gte mso 9]><xml> Normal 0 7.8 磅 0 2 false false false MicrosoftInternetExplorer4 </xml><![endif]--><!--[if gte mso 9]><![endif]--><style> <!-- /* Font Definitions */ &#64;font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1;} &#64;font-face {font-family:""&#64;宋体"; panose-1:2 1 6 0 3 1 1 1 1 1;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; font-size:10.5pt; font-family:"Times New Roman";} /* Page Definitions */ &#64;page {} &#64;page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt;} div.Section1 {page:Section1;} --> </style><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable { mso-style-parent:""; font-size:10.0pt; font-family:"Times New Roman";} </style> <![endif]-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="ProgId" content="Word.Document"><meta name="Generator" content="Microsoft Word 11"><meta name="Originator" content="Microsoft Word 11"><link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml"><!--[if gte mso 9]><xml> Normal 0 7.8 磅 0 2 false false false MicrosoftInternetExplorer4 </xml><![endif]--><!--[if gte mso 9]><![endif]--><style> <!-- /* Font Definitions */ &#64;font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1;} &#64;font-face {font-family:""&#64;宋体"; panose-1:2 1 6 0 3 1 1 1 1 1;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; font-size:10.5pt; font-family:"Times New Roman";} /* Page Definitions */ &#64;page {} &#64;page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt;} div.Section1 {page:Section1;} --> </style><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable { mso-style-parent:""; font-size:10.0pt; font-family:"Times New Roman";} </style> <![endif]-->

要注意的是,上述的三个Bean标签都将变量保存到了page范围内(也就是JSP内嵌对象pageContext中),并且不能改变变量的保存范围。读者在使用这三个Bean标签时应注意这一点。

二、访问Java对象

1.<bean:define>标签

<bean:define>标签用来将Java对象的属性值保存在变量中。<bean:define>标签有五个常用属性:

(1)id:变量名。

(2)name:Java对象名。

(3)property:Java对象属性名。

(4)scope:name所指的Java对象所在的访问,如果不指定,默认是page范围。

(5)toScope:id所指的变量要保存的范围,如果不指定,默认是page范围。

2.<bean:size>标签

<bean:size>标签用来获得集合(Map、Collection)或数组的长度。<bean:size>标签有两个常用的属性:

(1)id:一个Integer变量

(2)name:集合或数据的变量名。

下面的例子演示了如何使用本节所讲的两个Bean标签来访问Java对象。在<samples工程目录>目录中建立一个accessJavaObject.jsp文件,代码如下:

<!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --> <% @pagepageEncoding = " GBK " %>
<% @tagliburi = " http://struts.apache.org/tags-bean " prefix = " bean " %>
< html >
< head >
< title > 访问Java对象 </ title >
</ head >
< body >
<% -- 建立actionform.HtmlTagsForm对象实例 -- %>
< jsp:useBean id ="htmlTagsForm" class ="actionform.HtmlTagsForm" />
< jsp:setProperty name ="htmlTagsForm" property ="name" value ="李宁" />
<% -- 测试bean:define标签 -- %>
< bean:define id ="myBeanVar" name ="htmlTagsForm" property ="name" />
${myBeanVar}
<%
String []arr = new String [ 10 ];
pageContext.setAttribute(
" arr " ,arr);
%>
<% -- 测试bean:size标签 -- %>
< bean:size id ="length" name ="arr" />
${length}
</ body >
</ html >

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="ProgId" content="Word.Document"><meta name="Generator" content="Microsoft Word 11"><meta name="Originator" content="Microsoft Word 11"><link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml"><!--[if gte mso 9]><xml> Normal 0 7.8 磅 0 2 false false false MicrosoftInternetExplorer4 </xml><![endif]--><!--[if gte mso 9]><![endif]--><style> <!-- /* Font Definitions */ &#64;font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1;} &#64;font-face {font-family:""&#64;宋体"; panose-1:2 1 6 0 3 1 1 1 1 1;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; font-size:10.5pt; font-family:"Times New Roman";} /* Page Definitions */ &#64;page {} &#64;page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt;} div.Section1 {page:Section1;} --> </style><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable { mso-style-parent:""; font-size:10.0pt; font-family:"Times New Roman";} </style> <![endif]-->

在IE中输入如下的URL来测试accessJavaObject.jsp:

http://localhost:8080/samples/accessJavaObject.jsp

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="ProgId" content="Word.Document"> <meta name="Generator" content="Microsoft Word 11"> <meta name="Originator" content="Microsoft Word 11"> <link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml"> <!--[if gte mso 9]><xml> Normal 0 7.8 磅 0 2 false false false MicrosoftInternetExplorer4 </xml><![endif]--><!--[if gte mso 9]><![endif]--><style> <!-- /* Font Definitions */ &#64;font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1;} &#64;font-face {font-family:""&#64;宋体"; panose-1:2 1 6 0 3 1 1 1 1 1;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; font-size:10.5pt; font-family:"Times New Roman";} /* Page Definitions */ &#64;page {} &#64;page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt;} div.Section1 {page:Section1;} --> </style> <!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable { mso-style-parent:""; font-size:10.0pt; font-family:"Times New Roman";} </style> <![endif]-->

三、访问JSP内嵌对象和Struts配置对象


1.<bean:page>标签

<bean:page>标签用来建立一个page范围的变量,并可通过这个变量来访问JSP的内嵌对象。这个标签有两个属性:

(1)id:变量名。

(2)property:JSP内嵌对象名,必须是application、config,、request、response或session其中之一。

2.<bean:struts>标签

<bean:struts>标签用来建立一个page范围的变量,并可通过这个变量来访问Struts的三个配置对象。这个标签有四个属性:

(1)id:变量名。

(2)formBean:struts-config.xml文件中的<form-bean>标签的name属性值。如果指定这个属性,<bean:struts>会创建org.apache.struts.action.ActionFormBean类型的对象实例。

(3)mapping:struts-config.xml文件中的<action>标签的path属性值。如果指定这个属性,<bean:struts>会创建org.apache.struts.action.ActionMapping类型的对象实例。

(4)forward:struts-config.xml文件中的<global-forwards>标签的子标签<forward>的name属性值。如果指定这个属性,<bean:struts>会创建org.apache.struts.action.ActionForward类型的对象实例。

在使用<bean:struts>标签时应注意,在满足下面三种情况中的一种,<bean:struts>就会抛出异常:

(1)同时使用了formBean、mapping和forward中的两个或三个。

(2)未指定formBean、mapping和forward

(3)formBean、mapping或forward所指的标签不存在。

下面的例子演示了<bean:page>和<bean:struts>标签的使用方法,在<samples工程目录>目录中建立一个accessEmbeddedObject.jsp文件,代码如下:


<!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --> <% @pagepageEncoding = " GBK " %>
<% @tagliburi = " http://struts.apache.org/tags-bean " prefix = " bean " %>
< html >
< head >
< title > 访问JSP内嵌对象和Struts配置对象 </ title >
</ head >
< body >
< bean:page id ="myRequest" property ="request" />
myRequest.characterEncoding=${myRequest.characterEncoding}
< br >
myRequest.contextPath=${myRequest.contextPath}
<%
out.println(myRequest.getParameter(
" abc " ));
%>
< bean:struts id ="myHtmlTagsForm" formBean ="htmlTagsForm" />< br >
myHtmlTagsForm.type=${myHtmlTagsForm.type}
< br >
myHtmlTagsForm.getClass()=${myHtmlTagsForm.class}
< bean:struts id ="myHtmlTags" mapping ="/htmlTags" />< br >
myHtmlTags.type=${myHtmlTags.type}
< br >
myHtmlTags.getClass()=${myHtmlTags.class}
< bean:struts id ="myNewProduct" forward ="newProduct" />< br >
myNewProduct.path=${myNewProduct.path}
< br >
myNewProduct.getClass()=${myNewProduct.class}
</ body >
</ html >

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="ProgId" content="Word.Document"> <meta name="Generator" content="Microsoft Word 11"> <meta name="Originator" content="Microsoft Word 11"> <link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml"> <!--[if gte mso 9]><xml> Normal 0 7.8 磅 0 2 false false false MicrosoftInternetExplorer4 </xml><![endif]--><!--[if gte mso 9]><![endif]--><style> <!-- /* Font Definitions */ &#64;font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1;} &#64;font-face {font-family:""&#64;宋体"; panose-1:2 1 6 0 3 1 1 1 1 1;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; font-size:10.5pt; font-family:"Times New Roman";} /* Page Definitions */ &#64;page {} &#64;page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt;} div.Section1 {page:Section1;} --> </style> <!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable { mso-style-parent:""; font-size:10.0pt; font-family:"Times New Roman";} </style> <![endif]-->

四、访问Web资源和属性文件

1.<bean:include>标签

<bean:include>标签用于获得相对或绝对路径的Web资源,并将这些资源的内容保存到page范围的变量中。<bean:include>标签有四个常用的属性:

(1)id:变量名。

(2)href:Web资源的绝对路径。

(3)page:Web资源的相对路径。以“/”开头。

(4)forward:struts-config.xml文件<global-forwards>元素的子元素<forward>的name属性值。如果指定这个属性,<bean:include>标签会自动获得<forward>的path属性所指的Web资源的内容。

2.<bean:resource>标签

<bean:resource>标签和<bean:include>标签类似,也用来获得Web资源的内容,但和<bean:include>的不同之处是<bean:resource>在访问Web资源时(如JSP页面),并不执行这个JSP页面,而是将整个JSP页面的原始内容保存到变量中,而<bean:include>在访问这个JSP页面时,会先执行这个JSP页面,然后将JSP页面执行后的结果保存在变量中。因此,使用<bean:include>访问Web资源和在IE中输入相应的URL的效果是一样的。而<bean:resource>获得的是JSP页面的源代码。

<bean:resource>标签有三个属性:

(1)id:变量名。

(2)name:Web资源的相对路径。以“/”开头。

(3)input:如果指定input属性,id变量为java.io.InputStream类型,如果未指定input属性,id变量为String类型。

3.<bean:message>标签

<bean:message>标签用于从Java属性文件中获得字符串信息。要注意的是,<bean:message>标签获得字符串信息后,并不将所获得的信息保存在变量中,而是将其直接输出,也就是在执行JSP页面时,在生成客户端内容时,<bean:message>标签会被属性文件中的字符串信息代替。<bean:message>标签的常用属性如下:

(1)key:属性文件中的字符串信息键名。

(2)bundle:struts-config.xml文件中的<message-resources>标签的key值属值。如果不指定bundle属性,就使用默认的属性文件。

(3)name:用于获得键名的字符串变量名或对象实例变量名。<bean:message>标签除了从key属性中获得键名,还可以通过将key保存在指定范围的变量中,然后通过name属性获得这个key。

(4)property:获得key的属性名。如果name属性为对象实例变量名,则<bean:message>标签会从property所指的属性中获得key。

(5)scope:<bean:message>标签获得name变量的范围。默认值是page。

(6)arg0 ~ arg4:用于向带参数的字符串信息中传入参数值。分别对应于属性文件中的{0} ~ {4}。

下面的例子演示了本节所涉及到的三个标签的使用方法。在运行这个例子之前,先在<samples工程目录>"src"struts目录中建立一个MyResources.properties文件,并输入如下的内容:

<!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --> greet = helloworld
myGreet
= hello{ 0 }

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="ProgId" content="Word.Document"><meta name="Generator" content="Microsoft Word 11"><meta name="Originator" content="Microsoft Word 11"><link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml"><!--[if gte mso 9]><xml> Normal 0 7.8 磅 0 2 false false false MicrosoftInternetExplorer4 </xml><![endif]--><!--[if gte mso 9]><![endif]--><style> <!-- /* Font Definitions */ &#64;font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1;} &#64;font-face {font-family:""&#64;宋体"; panose-1:2 1 6 0 3 1 1 1 1 1;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; font-size:10.5pt; font-family:"Times New Roman";} /* Page Definitions */ &#64;page {} &#64;page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt;} div.Section1 {page:Section1;} --> </style><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable { mso-style-parent:""; font-size:10.0pt; font-family:"Times New Roman";} </style> <![endif]-->
然后在struts-config.xml中的<struts-config>元素中添加如下的子标签:

<!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --> < message-resources parameter ="struts.MyResources" key ="my" />

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="ProgId" content="Word.Document"><meta name="Generator" content="Microsoft Word 11"><meta name="Originator" content="Microsoft Word 11"><link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml"><!--[if gte mso 9]><xml> Normal 0 7.8 磅 0 2 false false false MicrosoftInternetExplorer4 </xml><![endif]--><!--[if gte mso 9]><![endif]--><style> <!-- /* Font Definitions */ &#64;font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1;} &#64;font-face {font-family:""&#64;宋体"; panose-1:2 1 6 0 3 1 1 1 1 1;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; font-size:10.5pt; font-family:"Times New Roman";} /* Page Definitions */ &#64;page {} &#64;page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt;} div.Section1 {page:Section1;} --> </style><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable { mso-style-parent:""; font-size:10.0pt; font-family:"Times New Roman";} </style> <![endif]-->

最后在<samples工程目录>中建立一个accessResources.jsp文件,代码如下:

<!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --> <% @pagepageEncoding = " GBK " %>
<% @pageimport = " actionform.HtmlTagsForm " %>
<% @tagliburi = " http://struts.apache.org/tags-bean " prefix = " bean " %>
< html >
< head >
< title > 访问Web资源和属性文件 </ title >
</ head >
< body >
< bean:include id ="myWebVar1"
href
="http://localhost:8080/samples/simpleValidation.jsp" />
< bean:include id ="myWebVar2" page ="/htmlTags.jsp" />
< bean:include id ="myWebVar3" forward ="newProduct" />
${myWebVar1}${myWebVar2}${myWebVar3}

< bean:resource id ="myResVar" name ="/htmlTags.jsp" />
${myResVar}
<% -- 从MyResources.properties中获得信息 -- %>
< bean:message bundle ="my" key ="greet" />
<% -- 从ErrorDescription.properties中获得信息 -- %>
< bean:message key ="error.email.invalid" />
< bean:message bundle ="my" key ="myGreet" arg0 ="李宁" />

<%
request.setAttribute(
" newGreet " , " greet " );
%>
< bean:message
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值