javaWEB项目感受

时间:2023-03-09 04:13:08
javaWEB项目感受

1.WEB-INF下的内容是受保护的,不能直接访问,可以通过转发的方式访问。

2.OGNL技术:

对象图像导航语言,是一种功能强大的表达式语言。可以让我们用非常简单的表达式访问对象层。

OGNL引擎访问对象的格式:Ognl.getValue("OGNL表达式",对象本身);

OGNL表达式:可以包含任何,包括各类表达式,计算公式,对象属相。某些方法等

步骤一:创建对象类,通过OGNL来取对应的数

package org.tedu.action;

import java.util.List;
import java.util.Map; public class Foo { private Integer id;
private String name;
private String[] array;
private List<String> list;
private Map<String,String> map; public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String[] getArray() {
return array;
}
public void setArray(String[] array) {
this.array = array;
}
public List<String> getList() {
return list;
}
public void setList(List<String> list) {
this.list = list;
}
public Map<String, String> getMap() {
return map;
}
public void setMap(Map<String, String> map) {
this.map = map;
} }

步骤二:具体去的方式

 package org.tedu.action;

 import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import ognl.Ognl;
import ognl.OgnlException; public class TestOGNL { public static void main(String[] args) throws OgnlException {
Foo f=new Foo();
f.setId(1);
f.setName("Bosh");
f.setArray(new String[]{"one","two","three"});
List<String> list=new ArrayList<String>();
list.add("a");
list.add("b");
list.add("c");
f.setList(list); Map<String,String> map=new HashMap<String,String>();
map.put("1", "java");
map.put("2", "hadoop");
map.put("3", "python");
f.setMap(map); System.out.println(Ognl.getValue("id", f));
System.out.println(Ognl.getValue("id+78", f));
System.out.println(Ognl.getValue("name", f));
System.out.println(Ognl.getValue("\"what is\" + name", f));
System.out.println(Ognl.getValue("array", f));
System.out.println(Ognl.getValue("list", f));
System.out.println(Ognl.getValue("map", f));
System.out.println(Ognl.getValue("name.toUpperCase()", f));
}
}

结果:

1
79
Bosh
what isBosh
[Ljava.lang.String;@12b82368
[a, b, c]
{3=python, 2=hadoop, 1=java}
BOSH