Skip to content

Commit

Permalink
读取xml
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaohuxing committed Mar 1, 2017
1 parent 03857fb commit fb798cf
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 68 deletions.
12 changes: 11 additions & 1 deletion group11/1178243325/DataStructure/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@

apply plugin: 'java'
apply plugin: 'eclipse'

jar {
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }}
manifest {
attributes 'Main-Class' : 'com.coding.Main'
attributes 'Main-Class' : 'com.Main'
}
}

repositories {
mavenCentral()
}

dependencies {
compile 'junit:junit:4.12'
compile 'dom4j:dom4j:1.6.1'
}

2 changes: 2 additions & 0 deletions group11/1178243325/DataStructure/src/main/java/com/Main.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com;

import com.coderising.litestruts.*;
import com.coderising.array.*;
public class Main {
public static void main(String[] args) {
Expand Down Expand Up @@ -47,5 +48,6 @@ public static void main(String[] args) {
System.out.print("\njoin测试:");
int[] jArray = new int[]{2, 3, 8};
System.out.print(ArrayUtil.join(jArray, "-"));
Struts.test();
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

import java.util.Map;



public class Struts {

public static View runAction(String actionName, Map<String,String> parameters) {

/*
0. 读取配置文件struts.xml
0. 读取配置文件struts.xml*/
String targetClassName = XmlUtil.parseXML("struts.xml", actionName);

/*
1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象)
据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是
("name"="test" , "password"="1234") ,
Expand All @@ -30,5 +30,5 @@ public static View runAction(String actionName, Map<String,String> parameters) {

return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.coderising.litestruts;

import java.io.*;
import java.util.*;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
public class XmlUtil {

public static String parseXML(String filePath, String actionName) {
try {
File file = new File(filePath);
SAXReader reader = new SAXReader();
Document doc = reader.read(file);
Element root = doc.getRootElement();
for (Iterator iter = root.elementIterator("action"); iter.hasNext();) {
Element element = (Element)iter.next();
Attribute nameAttr = element.attribute("name");
if (nameAttr.getValue().equals(actionName)) {
Attribute classAttr = element.attribute("class");
return classAttr.getValue();
}
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("parse error");
}
return null;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,25 @@ public class BinaryTreeNode {
public Object getData() {
return data;
}

public void setData(Object data) {
this.data = data;
}

public BinaryTreeNode getLeft() {
return left;
}

public void setLeft(BinaryTreeNode left) {
this.left = left;
}

public BinaryTreeNode getRight() {
return right;
}

public void setRight(BinaryTreeNode right) {
this.right = right;
}

public BinaryTreeNode insert(Object o){
return null;
}

}
11 changes: 11 additions & 0 deletions group11/1178243325/DataStructure/struts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<struts>
<action name="login" class="com.coderising.action.LoginAction">
<result name="success">/jsp/homepage.jsp</result>
<result name="fail">/jsp/showLogin.jsp</result>
</action>
<action name="logout" class="com.coderising.action.LogoutAction">
<result name="success">/jsp/welcome.jsp</result>
<result name="error">/jsp/error.jsp</result>
</action>
</struts>

0 comments on commit fb798cf

Please sign in to comment.