編寫一個簡單的javaEE加法程式

來源:互聯網
上載者:User

標籤:jdk   har   efault   row   version   1.0   return   準備   support   

一 、javaEE的安裝及環境配置

工具:

32位系統準備eclipse-jee-mars-2-win32.zip,64位系統準備eclipse-jee-mars-2-win32-x86_64.zip

jdk1.7

maven3.3.9.rar

m2.rar

環境配置:

1. 設定eclipse的設定檔eclipse.ini,修改虛擬機器路徑,在-vmargs之前添加

-vm E:\jee\jdk1.7\bin\javaw.exe

注意:用寫字板開啟修改,-vm有的電腦要換行,有的電腦不用換行

2. 啟動eclipse,設定maven

在菜單window-prefrences中搜尋“maven”,開啟“installations”選項進行設定

3.設定maven本地倉庫路徑

Maven本地倉庫預設在C:\Users\使用者名稱\.m2下,C盤空間通常很緊張,需要移到其它盤,步驟如下:

(1)修改Maven根目錄(E:\jee\maven-3.3.9)下的 conf檔案夾內的setting.xml檔案,新增一行:

<localRepository>e:\jee\.m2\repository</localRepository>

(2)修改Eclipse中的maven配置

在菜單window--prefrences中,開啟“maven--User settings”,如:

 

先點“User settings”設定項的“Browse…”按鈕,選擇maven的設定檔,再點下面的“Reindex”按鈕更新索引。

 二、編寫一個簡單的加法程式

建立maven項目:

1.選擇菜單file—new—maven project,勾選“Create a &simple project (skip archetype selection)"

2.建立maven項目,設定項目屬性如下 

加法程式關鍵代碼

AddAction.java

package com.cqvie.action;import com.opensymphony.xwork2.ActionSupport;public class AddrAction extends ActionSupport {    private String n1;    private String n2;    private String n;        public String getN1() {        return n1;    }    public void setN1(String n1) {        this.n1 = n1;    }    public String getN2() {        return n2;    }    public void setN2(String n2) {        this.n2 = n2;    }    public String getN() {        return n;    }    public void setN(String n) {        this.n = n;    }    /**     * 鐧誨綍     * @return     */    public String add() {        n=n1+n2;            return "n";    }}

add.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html>    <head>        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">        <title>登入介面</title>    </head>        <body>        <form action="add" method="post">            name:<input type="text" name="n1" />            name:<input type="text" name="n2" />                        <input type="submit" value="=" />        </form>    </body></html>

add_success.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><%-- <%@ taglib prefix="s" uri="/struts-tags" %> --%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html>    <head>        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">        <title>登入成功</title>    </head>        <body>        <%-- <s:form action="login" namespace="/" method="post">            <s:textfield name="name" label="name"></s:textfield>            <s:password name="password" label="password"></s:password>                        <s:submit value="Login"></s:submit>        </s:form> --%>        <s:property value="n"/>    </body></html>

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>  <!DOCTYPE struts PUBLIC      "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"      "http://struts.apache.org/dtds/struts-2.0.dtd"><struts>    <constant name="struts.i18n.encoding" value="utf-8"></constant>    <constant name="struts.multipart.maxSize" value="20971520" />    <constant name="struts.devMode" value="true" />    <package name="p_user" namespace="/" extends="struts-default">            <action name="add" class="com.cqvie.action.AddAction"            method="add">            <result name="success">                /add_success.jsp            </result>                            </action>            </package></struts>  

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>登入</title></head><body>    <a href="login">去登入</a></body></html>

3.運行項目

選擇菜單“Run”—“Run Configurations”,設定如:

4.在瀏覽器中查看結果

地址欄輸入“http://localhost:9527/add/”查看結果

 

編寫一個簡單的javaEE加法程式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.