zoukankan      html  css  js  c++  java
  • 应用Struts框架,开发一个加法器

    一、准备以下压缩包:

    1. JDK1.7
    2. Maven
    3. Eclipse

    二、安装

    1. 选择一个单独的工作盘并建立文件夹(只与本文件项目有关,不与其它地方的JDK、tomcat等发生关系)
    2. 设置eclipse的配置文件eclipse.ini,修改虚拟机路径,在-vmargs之前添加

             -vm E:jeejdk1.7injavaw.exe

    注意:1用写字板打开修改,-vm不要换行

          2以上方式依旧不行,可选择换行

    1. 启动eclipse,设置maven

           在菜单window-prefrences中搜索“maven”,打开“installations”选项进行设置

    1. 设置maven仓库路径

    (1)修改Maven根目录(E:jeemaven-3.3.9)下的 conf文件夹内的setting.xml文件,新增一行:

    <localRepository>e:jee.m2 epository</localRepository>

    1. 修改Eclipse中的maven配置

    在菜单windo->prefences中,打开“maven-User setting”,如下图:

     选中User Settings,点击“Browse”,选择刚配置的Maven文件,再点击下面的“Reindex”按钮进行更新索引。

    一、新建项目

     

    直接点击 ”next”:

     

    填写: Group id 主要是网址

           Artifact id 项目id

           Package 自动根据这两个生成,如下图:

    一、编写程序

    1. 首页代码如下:

    <html>

          <head>

               <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

               <title>计算器</title>

          </head>

          <body>

               <form action="login" method="post">

                     <input type="text" name="one" />

                        +

                     <input type="text" name="two" />

                     <input type="submit" value="计算" />

               </form>

          </body>

    </html> 

     2. 对于java文件中,新增UserAction.Java,内容如下:

    public class UserAction extends ActionSupport {

          private int one;

          private int two;

          private int san;

          public int getSan() {

               return san;

          }

          public void setSan(int san) {

               this.san = san;

          }

          public int getOne() {

               return one;

          }

          public void setOne(int one) {

               this.one = one;

          }

          public int getTwo() {

               return two;

          }

          public void setTwo(int two) {

               this.two = two;

          }

          public String login() {

               System.out.println("one->" + one);

            System.out.println("two->" + two);

                      if(one>0&&two>0){

                 san = one + two;

                 return "success";}

           else

                 return "error";

      }

    }

    3.在浏览器中查看结果

    地址栏输入“http://localhost:9527/struts-add/”查看结果

     

  • 相关阅读:
    Winform界面开发:如何在代码中获取自定义外观元素属性的值
    VCL组件DevExpress VCL发布v20.1.4,附高速下载
    WPF界面开发技巧分享——如何实现自定义DateEdit并自动更正值
    Web开发实用技能,看Kendo UI for jQuery组模板如何使用
    docker从C盘迁移到D盘
    ubuntu16.04中开启和关闭防火墙命令
    Linux安装与卸载 docker-compose
    在Docker容器bash中输入中文
    in()和exists()
    mysql遇见Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre的问题
  • 原文地址:https://www.cnblogs.com/bigbangtop/p/6508626.html
Copyright © 2011-2022 走看看