Struts标签使用

1.1. 页面跳转
  可以使用href、page、action三个属性实现struts视图层组件的跳转,三个属性的作用及区别为:① href使用该域名下的相对路径,路径前不需要加“/”,或链接至以http开头其它域名,href="index.jsp"、href="http: //www.baidu.com";② page使用该域名下的绝对路径,路径前需要加“/”;③ action使用该域名下的绝对路径,路径前需要加“/”,与page的区别是可以省略.do;为了生成“http://localhost: 8080/941ok/chat/questFriendIndex.do”这样的链接,分别使用href、page、action的实现如下:
  href="questFriendIndex.do";
  page="/chat/questFriendIndex.do";
  action="/chat/questFriendIndex"、action="/chat/questFriendIndex.do";

1.2. 参数传递
  ① 传递静态参数,直接写在URL里,例如:href="questFriendIndex.do?username=1&password=1";
  ② 传递单个动态参数,通过paramId,paramName和paramProperty属性传递Bean里的单个值。paramId属性告诉jsp编译引擎要传送的参数名称是什么,“?”号后面,“=”号前面的内容;paramName属性和paramProperty属性告诉编译引擎使用哪个Bean 的哪个属性值,构造“=”后面的内容。如果beanName的property beanProperty的值为beanPropertyValue,那么<html:link page="chat/questFriendIndex.do" paramId="param_name" paramName="beanName" paramProperty="beanProperty">对应的url是http://localhost: 8080/941ok/chat/questFriendIndex.do?param_name=beanPropertyValue;
  ③ 传递多个动态参数,通过name属性传递在request对象里设置的Map类型的对象里的多个参数;假设如果你定义下面的一个map:
Map mapName=new HashMap();
mapName.put("paramValue1","value1");
mapName.put("paramValue2","value2");
request.setAttribute("mapName",mapName);
在jsp页面有下面的一个链接:
<html:link action="/chat/questFriendIndex" name="mapName">
对以的链接是:
http://localhost:8080/941ok/chat/questFriendIndex.do?paramValue1=value1&paramValue2=value2

1.3. 示例应用结构
{$tomcat_home\webapps}
|__941ok
  |__WEB-INF
  |__chat
    |__index.jsp
    |__questFriendIndex.do
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值