• struts 学习


    1、在Struts2的Action中取得请求参数值的几种方法

     1 public class GetRequestParameterAction extends ActionSupport {
     2 
     3     private String bookName;
     4     private String bookPrice;
     5     
     6     public String getBookName() {
     7         return bookName;
     8     }
     9 
    10     public void setBookName(String bookName) {
    11         this.bookName = bookName;
    12     }
    13 
    14     public String getBookPrice() {
    15         return bookPrice;
    16     }
    17 
    18     public void setBookPrice(String bookPrice) {
    19         this.bookPrice = bookPrice;
    20     }
    21     
    22     
    23     public String  execute() throws Exception{
    24         
    25         
    26         //方式一: 将参数作为Action的类属性,让OGNL自动填充
    27          
    28         System.out.println("方法一,把参数作为Action的类属性,让OGNL自动填充:");
    29         System.out.println("bookName: "+this.bookName);
    30         System.out.println("bookPrice: " +this.bookPrice);
    31         
    32         
    33         //方法二:在Action中使用ActionContext得到parameterMap获取参数:
    34         ActionContext context=ActionContext.getContext();
    35         Map  parameterMap=context.getParameters();
    36         
    37         String bookName2[]=(String[])parameterMap.get("bookName");
    38         String bookPrice2[]=(String[])parameterMap.get("bookPrice");
    39         
    40         System.out.println("方法二,在Action中使用ActionContext得到parameterMap获取参数:");
    41         System.out.println("bookName: " +bookName2[0]);
    42         System.out.println("bookPrice: " +bookPrice2[0]);
    43         
    44         
    45         //方法三:在Action中取得HttpServletRequest对象,使用request.getParameter获取参数
    46         HttpServletRequest request = (HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST); 
    47          
    48         String bookName=request.getParameter("bookName");
    49         String bookPrice=request.getParameter("bookPrice");
    50         
    51         System.out.println("方法三,在Action中取得HttpServletRequest对象,使用request.getParameter获取参数:");
    52         System.out.println("bookName: " +bookName);
    53         System.out.println("bookPrice: " +bookPrice);
    54         return SUCCESS;
    55         
    56     }
    57 
    58 }

     2、Taglib Struts标签库

         学习使用,谢谢博主!

  • 相关阅读:
    HDU 1170 Balloon Comes!
    深入学习QWidget-1
    UI复习练习_优酷布局
    【IOS】 readonly IOS下实战入门
    Android--推断文本文件编码
    2、应用设置之属性、名词等解析
    QT国际化,中英文等多语言界面显示的方法
    利用Java编写简单的WebService实例
    隐式意图调用系统自带组件的各种Uri总结
    Spring MVC学习-----------springMVC-mvc.xml
  • 原文地址:https://www.cnblogs.com/xiaoyi115/p/3273473.html
Copyright © 2020-2023  润新知