zoukankan      html  css  js  c++  java
  • Struts2入门案例——基于Struts2任意两数据的代数和

    //ch11_1_Input.jsp
    <%
    @ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <html> <head> <title>提交两数据页面</title> </head> <body> <form action="add" method="post"> 请输入两个整数:<br><br> 加数:<input name="x"/><br><br> 被加数:<input name="y"/><br><br> <input type="submit" value="求和"> </form> </body> </html>
    //ch11_1_Positive.jsp
    <%@ page language="java"  pageEncoding="UTF-8"%>
    <%@ taglib prefix="s" uri="/struts-tags" %>
    <html>
      <head>
        <title>显示页面——代数和为非负整数</title>
      </head>
      
      <body>
            代数和为非负整数:<s:property value="sum"/>
      </body>
    </html>
    //ch11_1_Negative.jsp
    <%@ page language="java"  pageEncoding="UTF-8"%>
    <%@ taglib prefix="s" uri="/struts-tags" %>
    <html>
      <head>
        <title>显示页面——代数和为负整数</title>
      </head>
      
      <body>
            代数和为负整数:<s:property value="sum"/>
      </body>
    </html>
    //Ch11_1_Action.java
    package Action;
    
    public class Ch11_1_Action {
        private int x;
        private int y;
        private int sum;
        public int getX() {
            return x;
        }
        public int getY() {
            return y;
        }
        public void setY(int y) {
            this.y = y;
        }
        public int getSum() {
            return sum;
        }
        public void setX(int x) {
            this.x = x;
        }
        public String execute()
        {
            sum=x+y;
            if(sum>=0)
                return "+";
            else
                return "-";
        }    
    }
    <?xml version="1.0" encoding="UTF-8">
    <!DOCTYPE struts PUBLIC
       "-//Apache Software Foundation//DTD Struts Configuration2.3//EN"
        "http://struts.apche.org/dtds/struts-2.3.dtd">
    <struts>
             <package name="default"namespase="/" exetends="struts-default">
                    <action name="add" calss="Action.Ch11_1_Action">
                    <result name="+">/ch11_1_Positive.jsp</result>
                    <result name="-">/ch11_1_Negative.jsp</result>
    </struts>       
  • 相关阅读:
    Oracle Database 11g : SQL 基础
    Idea-Java接入银联支付的Demo
    Linux文件系统挂载管理
    Linux文件系统
    使用fdisk进行磁盘管理
    Vim文本编辑器
    Linux系统常用命令
    Linux系统目录架构
    Linux文件基本操作管理
    Linux文件系统的基本结构
  • 原文地址:https://www.cnblogs.com/liao-pxsoftware15/p/8068234.html
Copyright © 2011-2022 走看看