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>       
  • 相关阅读:
    php设置和获取cookie
    字符截取 支持UTF8/GBK
    PHP自毁程序
    php短信发送
    PHP版QQ互联OAuth示例代码分享
    javascript中window.open()与window.location.href的区别
    SpringBoot文件上传
    IDEA或Webstorm设置Ctrl+滚轮调整字体大小
    IDEA和WebStorm破解教程--激活80年(ideaIU-2018.3.6以及之前的版本)
    3 字节的 UTF-8 序列的字节 2 无效
  • 原文地址:https://www.cnblogs.com/liao-pxsoftware15/p/8068234.html
Copyright © 2011-2022 走看看