diff --git a/group14/857999411/SecondHomework/.classpath b/group14/857999411/SecondHomework/.classpath new file mode 100644 index 0000000000..158993c7d3 --- /dev/null +++ b/group14/857999411/SecondHomework/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/group14/857999411/SecondHomework/.gitignore b/group14/857999411/SecondHomework/.gitignore new file mode 100644 index 0000000000..ae3c172604 --- /dev/null +++ b/group14/857999411/SecondHomework/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/group14/857999411/SecondHomework/.project b/group14/857999411/SecondHomework/.project new file mode 100644 index 0000000000..1bcfdd57a3 --- /dev/null +++ b/group14/857999411/SecondHomework/.project @@ -0,0 +1,17 @@ + + + SecondHomework + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/group14/857999411/SecondHomework/.settings/org.eclipse.jdt.core.prefs b/group14/857999411/SecondHomework/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..3a21537071 --- /dev/null +++ b/group14/857999411/SecondHomework/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/group14/857999411/SecondHomework/lib/commons-beanutils-1.9.3.jar b/group14/857999411/SecondHomework/lib/commons-beanutils-1.9.3.jar new file mode 100644 index 0000000000..6728154e56 Binary files /dev/null and b/group14/857999411/SecondHomework/lib/commons-beanutils-1.9.3.jar differ diff --git a/group14/857999411/SecondHomework/lib/commons-logging-1.1.1.jar b/group14/857999411/SecondHomework/lib/commons-logging-1.1.1.jar new file mode 100644 index 0000000000..8758a96b70 Binary files /dev/null and b/group14/857999411/SecondHomework/lib/commons-logging-1.1.1.jar differ diff --git a/group14/857999411/SecondHomework/lib/dom4j-1.6.1.jar b/group14/857999411/SecondHomework/lib/dom4j-1.6.1.jar new file mode 100644 index 0000000000..c8c4dbb92d Binary files /dev/null and b/group14/857999411/SecondHomework/lib/dom4j-1.6.1.jar differ diff --git a/group14/857999411/SecondHomework/src/com/coderising/array/ArrayUtil.java b/group14/857999411/SecondHomework/src/com/coderising/array/ArrayUtil.java new file mode 100644 index 0000000000..95be832836 --- /dev/null +++ b/group14/857999411/SecondHomework/src/com/coderising/array/ArrayUtil.java @@ -0,0 +1,264 @@ +package com.coderising.array; + +import java.util.ArrayList; +import java.util.Arrays; + +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 len =origin.length; + int [] newArray =new int[len]; + + int j=0; + for(int i=len-1;i>=0;i--){ + if(j list = new ArrayList(); + + if(array1[0] != array2[0]){ + list.add(array1[0]); + list.add(array2[0]); + }else if(array1[0] == array2[0]){ + list.add(array1[0]); + } + + int i =1; + for(int j=1;j array2[j]){ + list.add(array2[j]); + list.add(array1[i]); + }else if(array1[i] < array2[j]){ + list.add(array1[i]); + list.add(array2[j]); + }else if(array1[i] == array2[j]){ + list.add(array1[i]); + } + i++; + } + + int[] newA =new int[list.size()]; + + for(int k=0;k2?f(n-1)+f(n-2):1; + } + public int[] fibonacci(int max){ + ArrayList list =new ArrayList(); + for(int i=1; i list = new ArrayList(); + + int j; + for(int i=2; i<=max; i++){ + j=2; + while(i%j != 0){ + j++; + } + if(j == i){ + list.add(i); + } + } + + for (Integer in : list) { + System.out.println(in); + } + + int num=0; + int [] newA =null; + for(int i=0; i list = new ArrayList(); + + int s; + for(int i=1;i<=10000;i++) + { + s=0; + for(int j=1;j parameters) throws Exception { + + /* + + 0. 读取配置文件struts.xml + + 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象) + 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是 + ("name"="test" , "password"="1234") , + 那就应该调用 setName和setPassword方法 + + 2. 通过反射调用对象的execute 方法, 并获得返回值,例如"success" + + 3. 通过反射找到对象的所有getter方法(例如 getMessage), + 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} , + 放到View对象的parameters + + 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp, + 放到View对象的jsp字段中。 + + */ + SAXReader reader = new SAXReader(); + Document doc = reader.read("./src/struts.xml"); + Element root = doc.getRootElement(); + Element el = root.element("action"); + Attribute attr = el.attribute("class"); + String value = attr.getValue(); + System.out.println(attr.getValue()); + + + Class clazz = Class.forName(value); + LoginAction login =(LoginAction) clazz.newInstance(); + + Method setN = clazz.getMethod("setName", String.class); + setN.invoke(login, "test"); + Method setP = clazz.getMethod("setPassword", String.class); + setP.invoke(login, "1234"); + + Method getM = clazz.getMethod("execute", null); + String str = (String) getM.invoke(login, null); + System.out.println(str); + + /*PropertyDescriptor pro = new PropertyDescriptor("name", LoginAction.class); + Method readM = pro.getReadMethod(); + String message = (String) readM.invoke(login, null);*/ + + String bean = BeanUtils.getProperty(login, "name"); + System.out.println(bean); + return null; + } + +} diff --git a/group14/857999411/SecondHomework/src/com/coderising/litestruts/StrutsTest.java b/group14/857999411/SecondHomework/src/com/coderising/litestruts/StrutsTest.java new file mode 100644 index 0000000000..92a6758a69 --- /dev/null +++ b/group14/857999411/SecondHomework/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() throws Exception { + + 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() throws Exception { + 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/group14/857999411/SecondHomework/src/com/coderising/litestruts/View.java b/group14/857999411/SecondHomework/src/com/coderising/litestruts/View.java new file mode 100644 index 0000000000..07df2a5dab --- /dev/null +++ b/group14/857999411/SecondHomework/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/group14/857999411/SecondHomework/src/com/coderising/litestruts/struts.xml b/group14/857999411/SecondHomework/src/com/coderising/litestruts/struts.xml new file mode 100644 index 0000000000..e5d9aebba8 --- /dev/null +++ b/group14/857999411/SecondHomework/src/com/coderising/litestruts/struts.xml @@ -0,0 +1,11 @@ + + + + /jsp/homepage.jsp + /jsp/showLogin.jsp + + + /jsp/welcome.jsp + /jsp/error.jsp + + \ No newline at end of file diff --git a/liuxin/src/com/coderising/litestruts/struts.xml b/liuxin/src/com/coderising/litestruts/struts.xml index dd598a3664..e5d9aebba8 100644 --- a/liuxin/src/com/coderising/litestruts/struts.xml +++ b/liuxin/src/com/coderising/litestruts/struts.xml @@ -1,10 +1,10 @@ - + /jsp/homepage.jsp /jsp/showLogin.jsp - + /jsp/welcome.jsp /jsp/error.jsp