• 第一个struct2程序


    【第1步】 安装Struts2
    
        这一步对于Struts1.x和Struts2都是必须的,只是安装的方法不同。Struts1的入口点是一个Servlet,而Struts2的入口点是一个过滤器(Filter)。因此,Struts2要按过滤器的方式配置。下面是在web.xml中配置Struts2的代码:
    
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.FilterDispatcher            
        </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    编写action类

    package action;
      
    import com.opensymphony.xwork2.ActionSupport;
      
    public class FirstAction extends ActionSupport
    {
        private int operand1;
        private int operand2;
      
        public String execute() throws Exception
        {
            if (getSum() >= 0)  // 如果代码数和是非负整数,跳到positive.jsp页面
            {
                return "positive";
            }
            else  // 如果代码数和是负整数,跳到negative.jsp页面
            {
                return "negative";
            }
        }
      
        public int getOperand1()
        {
            return operand1;
        }
      
        public void setOperand1(int operand1)
        {
            System.out.println(operand1);
              this.operand1 = operand1;
        }
      
        public int getOperand2()
        {
            return operand2;
        }  
        public void setOperand2(int operand2)
        {
            System.out.println(operand2);
            this.operand2 = operand2;
        }
        public int getSum()
        {
            return operand1 + operand2;  // 计算两个整数的代码数和
        }
    }
    

      。。。

  • 相关阅读:
    mysql view
    单点登录原理与简单实现
    复述记忆法
    英语细节锦集(基本时态的构成、元音辅音字母、)
    被动语态 动词的过去分词
    play后面加the不加the如何分辨
    正则表达式入门
    使用 lxml 中的 xpath 高效提取文本与标签属性值
    Android Studio 导入新工程项目
    winfrom Panel 问题
  • 原文地址:https://www.cnblogs.com/frankzone/p/8068103.html
Copyright © 2020-2023  润新知