Struts1第四天

常用struts标签:
struts-html:
 *1 <html:form> <==> <form>
  要求:编写该标签,必须创建对应的formBean,同时指定action属性的请求路径
  该标签中的action属性,不能直接跳转页面信息
  该标签中的action属性,指定跳转资源时,其绝对路径是以项目名开始
 2 <html:text> 
  要求:formBean中必须出现一个跟该控件同名的属性
 3 <html:radio>
  要求:formBean中必须出现一个跟该控件同名的属性
 4 <html:checkbox>
  要求:formBean中必须出现一个跟该控件同名的属性
  属性类型只能是数组
 5 <html:select>
  <html:option>
  要求:formBean中必须出现一个跟该控件同名的属性
  option中的值需要程序员在页面中手动指定
 6 <html:select property="salary">
  <html:options property="salarys">
  要求:formBean中必须出现两个属性,同时在formBean的无参构造方法中对数组、集合进行初始化。
  String salary;
  String[]/List/Set salarys;

  public Form(){
   //salarys = new String[]{'1000','2000'....}
   salarys = new ArrayList();
   salarys.add("1000");
   ....
  }
 7 <html:select property="salary">
  <html:optionsCollection property="salarys" label="name">

   formBean{
  private String salary;
  private Collection salarys;

  public FormBean(){
   salarys = new ArrayList();
   salarys.add(new Option("10000","10k"));
   salarys.add(new Option("20000","30k"));
  }
       }

   public class Option{
  private String name; //key属性的名字可以随意指定,只需在页面中的label中一致即可
  private String value; //value属性的名字必须是value
  set/get
  public Option(String name,String value){
   this.name = name;
   this.value = value;
  }
   }
struts-bean:
 *1 <bean:parameter name="username" id="uname"/>
  String uname = req.getParameter("username");
 *2 <bean:write name="uname"/>
  <%=uname%>
 *3 <bean:define id="a" toScope="session" value="aaa"></bean:define>
  <==>  session.setAttribute("a","aaa");
   <bean:write name="a" scope="session"/>
  <==>  session.getAttribute("a");
 4 <bean:define id="aa" toScope="request" scope="session" name="a"></bean:define>
  <==>
  String a = session.getAttribute("a");
  request.setAttribute("aa",a);
 5 <bean:write name="a">
  <==>pageContext.findAttribute("a");
  page-->request-->session-->application
 6 <bean:header name="Accept-Language" id="chars"/>
   <bean:write name="chars"/>

 7 <bean:cookie name="myCookie"  value="heheCookie" id="m"/>
  <==>
  Cookie c = new Cookie("m","heheCookie");
  resp.addCookie(c);
   <bean:write name="m" property="value"/>
  <==>
  Cookie[] cs = request.getCookies();
  for(Cookie c : cs){
   if(c.getName().equals("m")){
    <%=c.getValue()%>
   }
  }
strust-logic:

 

struts文件上传注意:
 1 上传页面中必须使用html:form,同时给该标签指定属性enctype="multipart/form-data",
 表示该页面提交给formBean的信息是文件信息,而非普通字符串
 
 2 formBean中必须使用org.apache.struts.upload.FormFile类型接受客户端发送的文件
 private FormFile file;
 
 3 action中,获取客户端上传文件的对象流:
 formBean.getFile().getInputStream();
   action中,获取客户端上传的文件名:
 formBean.getFile().getFileName();


将stuMgmt中的showAll.jsp,全部使用struts标签实现

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值