/**********************Example.java*********************/import java.io.BufferedWriter;
import java.io.OutputStreamWriter;import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;public class Example {
public Example(String templateFile) {
try {
VelocityEngine ve = new VelocityEngine();
ve.init(); VelocityContext context = new VelocityContext();
Customer c = new Customer();
c.setAddress("Addd");
c.setAge("18");
context.put("Customer", c);
Template template = null; try {
template = ve.getTemplate(templateFile, "gb2312");
} catch (ResourceNotFoundException rnfe) {
rnfe.printStackTrace();
} catch (ParseErrorException pee) {
pee.printStackTrace();
}
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
System.out));
if (template != null) {
template.merge(context, writer);
}
writer.flush();
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
} public static void main(String[] args) {
Example t = new Example(args[0]);
}
}
import java.io.OutputStreamWriter;import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;public class Example {
public Example(String templateFile) {
try {
VelocityEngine ve = new VelocityEngine();
ve.init(); VelocityContext context = new VelocityContext();
Customer c = new Customer();
c.setAddress("Addd");
c.setAge("18");
context.put("Customer", c);
Template template = null; try {
template = ve.getTemplate(templateFile, "gb2312");
} catch (ResourceNotFoundException rnfe) {
rnfe.printStackTrace();
} catch (ParseErrorException pee) {
pee.printStackTrace();
}
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
System.out));
if (template != null) {
template.merge(context, writer);
}
writer.flush();
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
} public static void main(String[] args) {
Example t = new Example(args[0]);
}
}
解决方案 »
- 启动报两个IO异常
- Struts2+spring整合问题!小弟虚心求教啊
- 关于struts2中自定义listener对xml文件的读取问题。 急求!
- servlet request.getParameter取出的都是乱码!?
- 拜师:找个java j2ee的师傅
- 为什么过滤器不能被调用?不知是哪骤错了,我是在struts中用的
- 看到好多兄弟都在找weblogic8的配置方法,我找到了一个《快速配置weblogic8_X的应用目录》,拿来和大家分享。希望兄弟们捧场。
- spring 事务一致性问题
- 很菜的问题……
- 如何在一个事务中同时进行EJB和jdbc的提交?
- 谁有sql Server 2000 的jdbc驱动,发个给我,谢谢!!!
- 是项目多得公司好,还是那种时间比较宽松,有很多时间自己学习的公司好
public class Customer {
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
private String age;
private String address;
public Customer() {
super();
}}
<body>
Address:$Customer.Address()
Age:$Customer.Age()
</body>
</html>
Address:$Customer.Address()
Age:$Customer.Age()
Address 和 Age 都没有解析,找了好久都没有找到原因
那位大虾帮忙ccps:偶素马甲