---
title: "struts1标签库"
author: "terryjs"
date: "2016-09-27T10:17:08Z"
tags: []
categories: ["非技术"]
slug: "struts1"
draft: true
lastmod: "2016-09-27T10:17:08Z"
id: 2327225
url: "https://terryjs.iteye.com/blog/2327225"
---

1、Bean标签库

Bean标签库中标签可以访问已经存在的JavaBean以及它们的属性，还可以

定义新的Bean，把它存放在用户指定的任何范围内，供网页或者其它元素访问，

Bean标签库分为以下三类:

   1) 用于访问HTTP请求信息或者JSP隐含对象的Bean标签

a) &lt;bean:cookie&gt;

用于检索发送到服务器端的Cookie，包括以下属性:

id: 定义一个Cookie类型的变量，这个变量又是作为将信息

存放在page范围内的key。

name: 指定Cookie的名字

value: 指定Cookie的默认值，如果name指定的Cookie不存在，

就使用value指定的属性值。

例如: &lt;bean:cookie id="cookie" name="cookieName"

value="defaultValue"/&gt;

先检索名为"cookieName"的Cookie是否存在，如果

存在，就把它的值赋给cookie变量的value值，如果

不存在，cookie变量的值就采用默认值"defaultValue"。

 

b) &lt;bean:header&gt;

用于检索HTTP请求中的Header信息，包括以下属性:

id: 定义一个存放信息的字符串变量，这个变量又是作为

将信息存放在page范围内的key。

name: 指定要检索的Header中的字段名字

例如: &lt;bean:header id="lang" name="Accept-Language"/&gt;

等于

String value =

(HttpServletRequest)request.getHeader("Accept-Language");

String lang = value;

pageContext.setAttribute("lang",value);

 

c) &lt;bean: parameter&gt;

用于检索HTTP的请求参数，包括以下属性:

id: 定义一个存放信息的字符串变量，这个变量又是作为

将信息存放在page范围内的key。

name: 指定请求的参数名

value: 指定请求参数的默认值

例如1: &lt;bean:parameter id="arg1" name="testarg"

value="noarg"/&gt;

等于

String temp = request.getParameter("testarg");

if(temp != null){

String arg1 = temp;

pageContext.setAttribute("arg1",temp);

}else{

String arg1 = "noarg";

pageContext.setAttribute("arg1","noarg");

}

例如2: &lt;bean:parameter id="arg2" multiple="yes"

name="testarg" value="noarg"/&gt;

arg2是一个存放所有request请求中参数值的字符串数组。

输出所有的参数值:

&lt;%

for(int i = 0; i &lt; arg2.length; i++){

out.write(arg2\[i] + "&lt;br&gt;");

}

%&gt;

 

d) &lt;bean:page&gt;

用于检索JSP隐含对象(如request、session、response)包括

以下属性:

id: 定义一个引用隐含对象的变量，这个变量又是作为

将信息存放在page范围中的key。

property: 指定隐含对象的名字，可选值包括application、

config、request、response和session。

例如: &lt;bean:page id="this\_session" property="session"/&gt;

&lt;bean:write name="this\_session" property="creationTime"/&gt;

表示定义了一个"this\_session"变量，它引用JSP中

的session隐含对象，接着输出该变量中属性

createTime的值(其实是session中属性createTime的值)。

 

2\) 用于访问Web应用资源的Bean标签

   a) &lt;bean:message&gt;

用于输出资源配置文件中的一条信息，&lt;bean:message&gt;标签的bundle

属性指定资源配置文件，它和Struts配置文件中的&lt;message-resources&gt;

元素的key属性匹配。如果没有设置bundle属性，就采用默认的资源配置文件。

Struts配置文件中配置了两个资源配置文件:

&lt;message-resources parameter="ApplicationResources"/&gt;

&lt;message-resources parameter="SpecialResources" key="special"/&gt;

第一个资源配置文件没有指定key属性，因此是默认的资源配置文件,

它的资源文件为ApplicationResources.properties。

第二个资源配置文件指定key属性为"special"，它的资源文件

为SpecialResources.properties。

内容: hello=Hello,ereryone!

 

&lt;bean:message&gt;标签三种使用方式:

a1) &lt;bean:message bundle="special" key="hello"/&gt;

bundle --&gt; &lt;message-resources&gt;中的key  

key --&gt; SpecialResources.properties中的hello

 

注意: 如果&lt;bean:message&gt;中设置了属性bundle，那么

&lt;message-resources&gt;中一定要设置属性key，否则运行

时会报错的。

 

a2) &lt;bean:message&gt;标签中的属性name指定一个scope中的key，value为

资源配置文件中的key。

例如: &lt;% request.setAttribute("stringBean","hello") %&gt;

&lt;bean:message bundle="special" name="stringBean"/&gt;

hello --&gt; SpecialResources.properties中的hello

 

a3) 同时指定&lt;bean:message&gt;标签的name和property，name指定

一个JavaBean，property指定JavaBean中的一个get方法，get方法

的返回值就是资源配置文件中的key。例如:

&lt;%

SomeBean bean = new SomeBean();

bean.setName("hello");

request.setAttribute("someBean",bean);

%&gt;

&lt;bean:message bundle="special" name="someBean"

property="name"/&gt;

bundle --&gt; &lt;message-resources&gt;中的key

name --&gt; request中的key(someBean)

property --&gt; bean的getName()

getName()返回值(hello) --&gt; 资源配置文件中key(hello)

 

   b) &lt;bean:resource&gt;

用于检索Web资源的内容，包括以下属性:

id: 定义一个代表Web资源的变量

name: 指定Web资源的路径

input: 如果没有设置input属性，则id属性定义的变量为字符串

类型；如果给input设置了值(可以是任意字符串)，则id

属性定义的变量为InputStream类型。

例如: &lt;bean:resource id="resource" name="/testpage1.jsp"/&gt;

resource变量代表"/testpage1.jsp"资源，由于没有设置input

属性，因此resource变量为字符串类型，它的值为testpage1.jsp

的源文件内容。

 

   c) &lt;bean:struts&gt;

用于检索Struts框架内在的对象，如ActionFormBean、ActionForward和

ActionMapping。包括以下属性:

id: 定义一个page范围内的变量，用来引用Struts框架内的对象。

formbean: 指定ActionFormBean对象，和Struts配置文件中的

&lt;form-bean&gt;元素匹配。

forward: 指定ActionForward对象，和Struts配置文件中的

&lt;global-forwards&gt;元素的&lt;forward&gt;子元素匹配。

mapping: 指定ActionMapping对象，和Struts配置文件中的

&lt;action&gt;元素匹配。

注意: 属性id必须和下面三个属性中的一个匹配

例如: &lt;bean:struts id="forward" forward="BeanResources"/&gt;

&lt;bean:write name="forward" property="path"/&gt;

以上代码的用属性id定义了一个"forward"变量，它引用

一个名为"BeanResources"的ActionForward对象，在Struts

文件中，与之匹配的&lt;forward&gt;元素为:

&lt;global-forward&gt;

&lt;forward name="BeanResources" path="/BeanResources.jsp"/&gt;

...

&lt;/global-forward&gt;

&lt;bean:write&gt;标签输出ActionForward对象的path属性值

 

   d) &lt;bean:include&gt;

和标准的JSP标签&lt;jsp:include&gt;很相似，都可以用来包含其他Web资源

的内容，区别在于&lt;bean:include&gt;标签把其它Web资源的内容存放在一

个变量中，而不是直接显示在页面上。包括以下属性:

id: 定义一个代表其它Web资源的位置

forward: 指定全局转发的路径，和Struts配置文件中的

&lt;global-forward&gt;元素中的&lt;forward&gt;子元素匹配。

page: 指定相对于当前应用的URL，以"/"开头。

href: 指定完整的URL

例如: &lt;bean:include id="p1" page="/page.jsp"/&gt;

&lt;bean:include id="p2" forward="success"/&gt;

&lt;bean:write name="p1" filter="false"/&gt;

&lt;bean:write name="p2" filter="false"/&gt;

 

3\) 用于定义或者输出JavaBean的Bean标签

   a) &lt;bean:define&gt;

   用于定义一个变量，属性id指定变量存放在scope中的key，toScope属性指定这个

   变量存放的范围，如果没有设置toScope属性，则这个变量存放在page

   范围内。给id属性定义的变量赋值有三种方式:

a1) 设置value属性 例如:

&lt;bean:define id="age" value="25"/&gt;

 

a2) 同时设置name和property属性。name属性指定一个已经存在的

Bean，property指定已经存在的Bean的某个属性，id作为key或者变量。

例如:

&lt;% request.setAttribute("sessionBean",session); %&gt;

&lt;bean:define id="contextBean" name="sessionBean"

property="servletContext"/&gt;

ServletContext Name:

&lt;bean:write name="contextBean"

property="servletContextName"/&gt;

contextBean属于ServletContext类型

 

a3) 同时设置name和type属性。name属性指定已经存在的JavaBean

，type属性指定这个JavaBean的完整的类名。id作为key或者变量。例如:

&lt;bean:define id="loginForm\_copy" name="loginForm"

type="com.briup.web.LoginForm"/&gt;

&lt;bean:write name="loginForm\_copy" property="username"/&gt;

该标签会依次在page、request、session和application范围

中根据key(loginForm)来查找LoginForm的对象，也可以通过

属性scope来指定一个查找的范围。

注意: 属性id定义的变量也是LoginForm的对象变量(对象引用)。

 

   b) &lt;bean:write&gt;

用于在页面上输出某个Bean或者其属性的内容。

例如: &lt;bean:write id="length" name="list"/&gt;

&lt;bean:write name="student" property="xh"/&gt;

&lt;bean:write format="#.####" name="employee"

property="salary"/&gt;

&lt;bean:write format="MM-dd-yyyyy hh:mm:ss"

name="now" property="time"/&gt;

注意: 该标签自动会从page、request、session和application

范围中根据name指定的key去查找对应的对象，也可以用

scope属性来限定某个范围。

另外，属性filter: true表示将html中的标记作为普通字符显示

false表示不会把html中的标记作为普通字符显示，默认为true。

 

   c) &lt;bean:size&gt;

用于获得Map、Collection或者数组的长度。包括以下属性:

id: 定义一个Integer类型的变量

name: 指定已经存在的Map、Collection或者数组变量

例如: &lt;bean:size id="length" name="list"/&gt;

&lt;bean:write name="length"/&gt;

 

2、HTML标签库

该标签库可以和标准的HTML标记完成相同的功能，主要分为以下几类:

   1) 用于生成基本的HTML的标签

a) &lt;html:html&gt;

用于在页面的开头生成HTML的&lt;html&gt;元素，该标签有一个属性

lang来显示用户显示的语言。

例如: &lt;html:html lang="true"/&gt;

如果用户的浏览器使用中文，那么该代码在运行时被解析为

&lt;html lang="zh-CN"&gt;

 

b) &lt;html:base&gt;

用于在页面的&lt;head&gt;部分生成&lt;base&gt;元素，用于生成当前页面

的绝对URL路径。

例如: &lt;html:base="http://localhost:8080/jsp"/&gt;

那么使用该base的页面已经将URL定位到应用程序jsp

的根目录下面，要从该页面再去访问其它资源，只要

使用相对路径即可。

c) &lt;html:link&gt;

用于生成HTML的&lt;a&gt;元素，包括以下的属性:

forward: 指定全局的转发链接，对应于Struts配置文件中

的&lt;global-forwards&gt;元素

href: 指定完整的URL链接

page: 指定相对于当前应用的URL

例如:

c1) &lt;html:link forward="index"&gt;

Link to Global ActionForward

&lt;/html:link&gt;

index对应于struts-config.xml中:

全局: &lt;forward name="index" path="index.jsp"&gt;

 

上述标签会自动生成HTML代码:

&lt;a href="/app/index.jsp"&gt;

Link to Global ActionForward

&lt;/a&gt;

 

c2) &lt;html:link href="http://localhost:8080/app/index.jsp"&gt;

Generate an "href" link

&lt;/html&gt;

生成的HTML代码如下:

&lt;a href="http://localhost:8080/app/index.jsp"&gt;

Generate an "href" link

&lt;/a&gt;

 

c3) &lt;html:link page="/login.do"&gt;

A relative link

&lt;/html:link&gt;

生成的HTML代码如下:

&lt;a href="/app/login.do"&gt;

Generate an "href" link

&lt;/a&gt;

使用该标签的优点:

b1) 应许再URL中以多种方式包含请求参数

b2) 在当前浏览器关闭Cookie时，会自动重写URL，把

jsessionid作为请求参数包含在URL中，用于跟踪

用户的状态(除了href属性)。

 

d) &lt;html:img&gt;

用于在HTML中嵌入图片

例如:

d1) &lt;html:img page="/girl.gif"/&gt;

生成HTML代码如下:

&lt;img src="/app/girl.gif"/&gt;

d2) &lt;html:img src="/app/girl.gif"

paramId="orderid" paramName="3"/&gt;

生成HTML代码如下:

&lt;img src="/app/girl.gif?orderid=3"/&gt;

 

   2) 用于生成HTML表单的标签

a) &lt;html:form&gt;

生成HTML&lt;form&gt;元素

例如: &lt;html:form action="/login"&gt;

生成的HTML代码如下:

&lt;form name="loginForm" method="POST"

action="/app/login.do"&gt;

对应于struts-config.xml中部分代码:

&lt;action path="/login"

type="com.briup.web.action.LoginAction"

name="loginForm"

scope="request"

input="/login.jsp"

validate="true"&gt;

&lt;forward name="success" path="/member\_activity.jsp"/&gt;

&lt;/action&gt;

 

b) &lt;html:text&gt;

生成HTML&lt;input type="text"&gt;元素

例如: &lt;html:text property="age"/&gt;

property属性指定的字段和ActionForm中的属性匹配

生成HTML代码如下:

&lt;input type="text" name="age"

value="ActionForm中属性age的值"/&gt;

 

c) &lt;html:hidden&gt;

生成HTML&lt;input type="hidden"&gt;元素

例如: &lt;html:hidden property="age"/&gt;

生成HTML代码如下:

&lt;input type="hidden" name="age" value="同上"/&gt;

 

d) &lt;html:submit&gt;

生成HTML&lt;input type="submit"&gt;元素

例如: &lt;html:submit&gt;提交&lt;/html:submit&gt;

生成HTML代码如下:

&lt;input type="submit" name="submit" value="提交"/&gt;

 

e) &lt;html:cancel&gt;

在表单上生成取消按钮

例如: &lt;html:cancel&gt;Cancel&lt;/html:cancel&gt;

生成HTML代码如下:

&lt;input type="submit"

name="org.apache.struts.taglib.html.CANCEL"

value="Cancel"/&gt;

注意: 在Action类中，应该以编程的方式来处理取消事件。

 

f) &lt;html:reset&gt;

生成HTML&lt;input type="reset"&gt;元素

例如: &lt;html:reset&gt;重置&lt;/html:reset&gt;

生成HTML代码如下:

&lt;input type="reset" name="reset" value="重置"/&gt;

 

g) &lt;html:checkbox&gt; 生成HTML&lt;input type="checkbox"&gt;元素

 

h) &lt;html:multibox&gt; 在表单上生成复选框元素

 

i) &lt;html:radio&gt; 生成HTML&lt;input type="radio"&gt;元素

 

j) &lt;html:select&gt; 生成HTML&lt;select&gt;元素

 

k) &lt;html:option&gt; 生成HTML&lt;option&gt;元素

 

l) &lt;html:options&gt; 生成一组HTML&lt;option&gt;元素

 

m) &lt;html:optionsCollection&gt; 生成一组HTML&lt;option&gt;元素

 

n) &lt;html:file&gt; 实现将本地文件上传到服务器端

 

&lt;html:form action="sendFile.do" method="POST"

enctype="multipart/form-data"&gt;

&lt;html:file property="file"/&gt;

&lt;/html:form&gt;

 

使用注意: n1) &lt;html:file&gt;必须嵌套在&lt;html:form&gt;中

n2) &lt;html:form&gt;标签的method属性必须为"POST"

n3) &lt;html:form&gt;标签的编码类型enctype必须设置

为"multipart/form-data"

n4) &lt;html:file&gt;标签必须设置property属性，这个

属性和ActionForm中FormFile类型的属性对应。

 

在ActionForm中必须配置:

private FormFile file;

public FormFile getFile(){return file;}

public void setFile(FormFile file){this.file = file;}

 

在Action中的处理:

FormFile file = registerForm.getFile();

//获得上传文件的名字

String fname = file.getFileName();

//从file中获得输入流

InputStream is = file.getInputStream();

//构造一个输出流，并指定上传文件在服务器端存放路径

OutputStream os = new FileOutputStream(dir + "/" + fname);

//从is中读取字节流后写入到os中

 

注意: 上述标签要使用在&lt;html:form&gt;标签中，但是在&lt;html:form&gt;标签中也可以使用标准的

html标记(如:&lt;input type="text"/&gt;等)。

 

   3) 显示错误或者正常消息的标签

a) &lt;html:errors&gt;

该标签在request和session范围内查找ActionMessages或者

子类ActionErrors的对象，再从中读取ActionMessage对象，

把ActionMessage对象中封装的的错误消息显示在页面上。

该标签处理类获取ActionMessages对象的代码如下:

ActionMessages errors =

TagUtils.getInstance().getActionMessages(pageContext,name);

参数name指定ActionMessages对象存放在request和session

范围中的key，默认值为Globals.ERROR\_KEY。

 

在ActionForm和Action中都可以生成ActionMessages对象，在

ActionForm中的validate()验证方法返回ActionErrors对象，Struts的

控制组件RequestProcessor把ActionErrors对象存放在request范围内，

存放时的key为Globals.ERROR\_KEY

(如: request.setAttribute(Globals.ERROR\_KEY,errors))。

 

&lt;html:errors&gt;标签中包括的属性:

name: 指定ActionMessages对象存放在request或者session范围

中的key，默认值为Globals.ERROR\_KEY。

property: 指定显示消息的属性，若没有设置，将显示ActionMessages

对象中所有的ActionMessage。

bundle: 指定资源配置文件，如果没有设置此项，将从Web应用

默认的资源配置文件中获得消息。

语法: errors.add(消息属性，消息);

如: errors.add(ActionMessages.GLOBAL\_MESSAGE,

new ActionMessage("error.error1"));

errors.add(ActionMessages.GLOBAL\_MESSAGE,

new ActionMessage("error.error2"));

saveErrors(request,errors);

注意: 同一个消息属性可以对应多条消息

 

使用&lt;html:errors&gt;的三种方法:

a1) 显示全局消息

全局消息指的是不和特定表单字段关联的消息，消息属性为

ActionMessages.GLOBAL\_MESSAGE。设置方式:

errors.add(ActionMessages.GLOBAL\_MESSAGE,

new ActionMessage("error.global"));

ActionMessages.GLOBAL\_MESSAGE是一个常量，它的值为

org.apache.struts.action.GLOBAL\_MESSAGE，代表全局消息。

在页面中显示该消息的方式:

&lt;html:errors property="org.apache.struts.action.GLOBAL\_MESSAGE"/&gt;

 

2\) 显示所有的消息

如果在&lt;html:errors/&gt;标签中没有设置property属性，将显示

ActionMessages对象中所有的消息。页面中显示消息方式:

&lt;html:errors bundle="special"/&gt;

指定了特定的资源配置文件，在struts-config.xml文件中

配置为:&lt;message-resources parameter="SpecialErrors"

key="special"/&gt;

 

3\) 显示和特定表单字段关联的消息

errros.add("name",new ActionMessage("error.name"));

页面中显示消息方式:

&lt;html:errors property="name" bundle="special"/&gt;

 

b) &lt;html:messages&gt;

和&lt;html:errors&gt;相似，也在页面上来显示消息，

使用例子:

&lt;html:messages id="message" name="key" message="true"&gt;

&lt;bean:write name="message"/&gt;

&lt;/html:messages&gt;

该标签包括以下属性:

name: 指定ActionMessages对象存放在request或者session中

的key。标签处理类将根据这一属性key来检索request

或者session范围的ActionMessages对象。

message: 指定消息的来源。如果为true，则从request或者

session范围内检索出属性key为Globals.MESSAGE\_KEY

的ActionMessages对象，此时属性name无效；如果

为false，则根据属性name来检索ActionMessages对象，

如果此时没有设置name属性，将采用默认值Globals.ERROR\_KEY。

message属性的默认值为false。

id: 用来命名从消息集合中检索出的每个ActionMessage对象，

它和&lt;bean:write&gt;标签的name属性匹配。在上述例子中，

&lt;html:messages&gt;标签的处理类每次从消息集合中取出一个

ActionMessage对象，并通过id把它命名为"message"，

&lt;bean:write&gt;标签接着把这个名为"message"的ActionMessage

对象的消息输出到页面上。

 

ActionMessages messages = new ActionMessages();

messages.add(ActionMessages.GLOBAL\_MESSAGE,

new ActionMessage("error.error1"));

saveMessages(request,messages);

protected void saveMessages(HttpServletRequest request,

ActionMessages messages){

...

request.setAttribute

(Globals.MESSAGE\_KEY,messages);

}

 

3、Logic标签库

该标签库中的标签可以根据特定的逻辑条件来控制输出页面的内容，或者

   循环遍历集合中所有的元素。Logic标签库中的标签分为以下几类:

1\) 进行比较运算的Logic标签

a) &lt;logic:equal&gt; 比较变量是否等于指定的常量

例如:

a1) &lt;% request.setAttribute("number",new Integer(100));%&gt;

&lt;logic:equal name="number" value="100"&gt;

The value of number is 100

&lt;/logic:equal&gt;

 

a2) &lt;%

Student student = new Student();

stu.setName("jack");

request.setAttribute("student",student);

%&gt;

&lt;logic:equal name="student" property="name"

value="jack"&gt;

The name of student is jack

&lt;/logic:equal&gt;

 

b) &lt;logic:notEqual&gt; 比较变量是否不等于指定的常量

c) &lt;logic:greaterEqual&gt; 比较变量是否大于或者等于指定的常量

d) &lt;logic:greaterThan&gt; 比较变量是否大于指定的常量

e) &lt;logic:lessEqual&gt; 比较变量是否小于或者等于指定的常量

f) &lt;logic:lessThan&gt; 比较变量是否小于指定的常量

 

2\) 进行字符串匹配的Logic标签

a) &lt;logic:match&gt; 判断变量中是否包含指定的常量字符串

例如:

&lt;% request.setAttribute("username","jackWang")%&gt;

&lt;logic:match name="username" scope="request"

value="jack"&gt;

match is right!

&lt;/logic:match&gt;

 

b) &lt;logic:notMatch&gt; 判断变量中是否不包含指定的常量字符串

 

3\) 判断指定内容是否存在的Logic标签

a) &lt;logic:empty&gt; 判断指定的变量是否为null或者为""。

例如: &lt;%

request.setAttribute("emptyString","");

或者

request.setAttribute("emptyString",null);

%&gt;

&lt;logic:empty name="emptyString"&gt;

The vlaue of emptyString is empty

&lt;/logic:empty&gt;

 

b) &lt;logic:notEmpty&gt; 判断指定的变量是否不为null或者不是""。

c) &lt;logic:present&gt; 判断指定的安全角色、用户、Cookie、HTTP

请求Header或者JavaBean是否存在。

d) &lt;logic:notPresent&gt; 判断指定的安全角色、用户、Cookie、HTTP

请求Header或者JavaBean是否不存在。

e) &lt;logic:messagesPresent&gt; 判断指定的消息是否存在

f) &lt;logic:messagesNotPresent&gt; 判断指定的消息是否不存在

 

4\) 进行循环遍历的Logic标签

&lt;logic:iterate&gt;是Logic标签库中最复杂的标签，也是用途最广

的一个标签，它能够在一个循环中遍历数组、Collection、Enumeration

Iterator或者Map中的所有元素。

a) 遍历数组

&lt;%

String\[] colors =

new String\[]{"red","yellow","green"};

List list = new ArrayList();

list.add("a");

list.add("b")

Map map = new HashMap();

map.put("1","a");

map.put("2","b");

request.setAttribute("colors",colors);

request.setAttribute("list",list);

request.setAttribute("map",map);

%&gt;

&lt;logic:iterate id="color" name="colors"&gt;

&lt;bean:write name="color"/&gt;

&lt;/logic:iterate&gt;

 

b) 遍历Collection

&lt;logic:iterate id="element" name="list" scope="page|request|session|applicatoin"&gt;

&lt;bean:write name="element"/&gt;

&lt;/logic:iterate&gt;

 

c) 遍历Map

&lt;logic:iterate id="entry" indexId="index"

name="map" scope="page|request|session|applicatoin"&gt;

&lt;bean:write name="entry" property="key"/&gt;

&lt;bean:write name="entry" property="value"/&gt;

&lt;/logic:iterate&gt;

属性scope省去不写，默认从page、request、session和application查找

 

 

5\) 进行请求转发或者重定向的Logic标签

a) &lt;logic:forward&gt; 进行请求转发

例如: &lt;logic:forward name="index"/&gt;

属性name指定的值为请求转发的全局目标资源，与Struts配置

文件中的&lt;global-forward&gt;元素中的&lt;forward&gt;子元素匹配。

&lt;global-forwards&gt;

&lt;forward name="index" path="/index.jsp"/&gt;

...

&lt;/global-forwards&gt;

 

b) &lt;logic:redirect&gt; 进行请求重定向

它包括forward、href和page三个属性，这三个属性的使用

方法和&lt;html:link&gt;标签中forward、href和page属性的用法很相似。

例如: &lt;logic:redirect href="http://localhost:8080/app/index.jsp"/&gt;