diff --git a/group09/790466157/src/com/coderising/array/ArrayUtil.java b/group09/790466157/src/com/coderising/array/ArrayUtil.java new file mode 100644 index 0000000000..e50070bdbd --- /dev/null +++ b/group09/790466157/src/com/coderising/array/ArrayUtil.java @@ -0,0 +1,263 @@ +package com.coderising.array; +import java.util.*; + +public class ArrayUtil { + + /** + * 给定一个整形数组a , 对该数组的值进行置换 + 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7] + 如果 a = [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7] + * @param origin + * @return + */ + public void reverseArray(int[] origin){ + int[] origin1 = {7,9,30,3}; + //交换数组元素 + for (int i = 0; i < origin1.length/2; i++){ + int tmp = origin1[i]; + origin1[i] = origin1[origin1.length-i-1]; + origin1[origin1.length-i-1] = tmp; + } + System.out.println(Arrays.toString(origin1)); + } + + /** + * 现在有如下的一个数组: int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5} + * 要求将以上数组中值为0的项去掉,将不为0的值存入一个新的数组,生成的新数组为: + * {1,3,4,5,6,6,5,4,7,6,7,5} + * @param oldArray + * @return + */ + + public int[] removeZero(int[] oldArray){ + int[] oldArray1 = {1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5}; + int newArrayLength = getLength(oldArray1); + int[] newArray = getNewArray(oldArray1, newArrayLength); + print(oldArray1); + print(newArray); + return newArray; + } + + public static int getLength(int[] array){ + int num = 0; + for(int i = 0 ; i < array.length;i++){ + if(array[i] != 0){ + num++; + } + } + return num; + } + + public static int[] getNewArray(int[] array,int num){ + int[] newArray = new int[num]; + int index = 0; + for(int i = 0; i < array.length; i ++){ + if(array[i]!=0){ + newArray[index] = array[i]; + index++; + } + } + return newArray; + } + public static void print(int [] array){ + for(int i : array){ + System.out.print(i+" "); + } + System.out.println(); + } + + + /** + * 给定两个已经排序好的整形数组, a1和a2 , 创建一个新的数组a3, 使得a3 包含a1和a2 的所有元素, 并且仍然是有序的 + * 例如 a1 = [3, 5, 7,8] a2 = [4, 5, 6,7] 则 a3 为[3,4,5,6,7,8] , 注意: 已经消除了重复 + * @param array1 + * @param array2 + * @return + */ + + public int[] merge(int[] array1, int[] array2){ + int[] a={10,20,30,40,50}; + int[] b={10,20,60}; + int[] c = new int[a.length+b.length-cf(a,b)*2]; + int index = 0; + for (int i=0;i 0) { + buf.append(separator); + } + if (array[i] != null) { + buf.append(array[i]); + } + } + return buf.toString(); + } + + +} \ No newline at end of file diff --git a/group09/790466157/src/com/coderising/litestruts/LoginAction.java b/group09/790466157/src/com/coderising/litestruts/LoginAction.java new file mode 100644 index 0000000000..dcdbe226ed --- /dev/null +++ b/group09/790466157/src/com/coderising/litestruts/LoginAction.java @@ -0,0 +1,39 @@ +package com.coderising.litestruts; + +/** + * 杩欐槸涓涓敤鏉ュ睍绀虹櫥褰曠殑涓氬姟绫伙紝 鍏朵腑鐨勭敤鎴峰悕鍜屽瘑鐮侀兘鏄‖缂栫爜鐨勩 + * @author liuxin + * + */ +public class LoginAction{ + private String name ; + private String password; + private String message; + + public String getName() { + return name; + } + + public String getPassword() { + return password; + } + + public String execute(){ + if("test".equals(name) && "1234".equals(password)){ + this.message = "login successful"; + return "success"; + } + this.message = "login failed,please check your user/pwd"; + return "fail"; + } + + public void setName(String name){ + this.name = name; + } + public void setPassword(String password){ + this.password = password; + } + public String getMessage(){ + return this.message; + } +} diff --git a/group09/790466157/src/com/coderising/litestruts/SAX.java b/group09/790466157/src/com/coderising/litestruts/SAX.java new file mode 100644 index 0000000000..ab3f0c1044 --- /dev/null +++ b/group09/790466157/src/com/coderising/litestruts/SAX.java @@ -0,0 +1,30 @@ +package com.coderising.litestruts; +import org.xml.sax.helpers.DefaultHandler; +import org.xml.sax.Attributes; +public class SAX extends DefaultHandler { + //文档开始事件处理方法 + public void startDocument() { + System.out.println("文档开始 "); + } + //文档结束事件处理方法 + public void endDocument() { + System.out.println("文档结束"); + } + //元素开始事件处理方法 + public void startElement(String uri, String localName, String qname, Attributes attr) + { System.out.println("元素开始: 本地名: " + localName + " 限定名: " + qname + " 命名空间URI: "+uri); + int attrCount = attr.getLength(); + if(attrCount>0) { + System.out.println("属性:"); + for(int i = 0 ; i parameters) { + + /* + + 0. 读取配置文件struts.xml + + 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象) + 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是 + ("name"="test" , "password"="1234") , + 那就应该调用 setName和setPassword方法 + + 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success" + + 3. 通过反射找到对象的所有getter方法(例如 getMessage), + 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} , + 放到View对象的parameters + + 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp, + 放到View对象的jsp字段中。 + + */ + + + return null; + } + +} diff --git a/group09/790466157/src/com/coderising/litestruts/StrutsTest.java b/group09/790466157/src/com/coderising/litestruts/StrutsTest.java new file mode 100644 index 0000000000..b8c81faf3c --- /dev/null +++ b/group09/790466157/src/com/coderising/litestruts/StrutsTest.java @@ -0,0 +1,43 @@ +package com.coderising.litestruts; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Test; + + + + + +public class StrutsTest { + + @Test + public void testLoginActionSuccess() { + + String actionName = "login"; + + Map params = new HashMap(); + params.put("name","test"); + params.put("password","1234"); + + + View view = Struts.runAction(actionName,params); + + Assert.assertEquals("/jsp/homepage.jsp", view.getJsp()); + Assert.assertEquals("login successful", view.getParameters().get("message")); + } + + @Test + public void testLoginActionFailed() { + String actionName = "login"; + Map params = new HashMap(); + params.put("name","test"); + params.put("password","123456"); //瀵嗙爜鍜岄璁剧殑涓嶄竴鑷 + + View view = Struts.runAction(actionName,params); + + Assert.assertEquals("/jsp/showLogin.jsp", view.getJsp()); + Assert.assertEquals("login failed,please check your user/pwd", view.getParameters().get("message")); + } +} diff --git a/group09/790466157/src/com/coderising/litestruts/View.java b/group09/790466157/src/com/coderising/litestruts/View.java new file mode 100644 index 0000000000..07df2a5dab --- /dev/null +++ b/group09/790466157/src/com/coderising/litestruts/View.java @@ -0,0 +1,23 @@ +package com.coderising.litestruts; + +import java.util.Map; + +public class View { + private String jsp; + private Map parameters; + + public String getJsp() { + return jsp; + } + public View setJsp(String jsp) { + this.jsp = jsp; + return this; + } + public Map getParameters() { + return parameters; + } + public View setParameters(Map parameters) { + this.parameters = parameters; + return this; + } +} diff --git a/group09/790466157/src/struts.xml b/group09/790466157/src/struts.xml new file mode 100644 index 0000000000..dd598a3664 --- /dev/null +++ b/group09/790466157/src/struts.xml @@ -0,0 +1,11 @@ + + + + /jsp/homepage.jsp + /jsp/showLogin.jsp + + + /jsp/welcome.jsp + /jsp/error.jsp + + \ No newline at end of file