不是有个VelocityViewServlet(具体记不清了,到google上查查)的Velocity引擎(类似于jsp引擎),用它就不用自己编码来处理.vm文件了,直接把.vm文件映射到这个Servlet就行了。
解决方案 »
- 求教 jsf标签怎么存js变量
- 请教关于layout的问题
- 关于超过4000字的字符内容存储的问题.
- iReport高手进,如何根据Header部分的数据决定detail部分的循环数据是否完全显示?
- 用javascript怎么解决这个问题
- 求救
- 菜菜问题,大家帮忙!
- 希望大家关注:tomcat和apache整合后的一些问题,很重要!
- jdbc与SQLServer 7.0连接问题 各位大大请来帮忙,万分感谢!
- Tomcat上面只能访问html页面访问不了jsp页该怎么办??大神们
- jsp在何处查找javabean? javabean生成的class放在那里?
- 请问:那里可以找到文档编排的JSP源码?
--------------------------------------------------
import java.io.StringWriter;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;public class HelloWorld {
public static void main(String[] args) throws Exception {/* first, get and initialize an engine */
VelocityEngine ve = new VelocityEngine();
ve.init(); Template t = ve.getTemplate("HelloWorld.vm");/* create a context and add data */
VelocityContext context = new VelocityContext();
context.put("name", "Eiffel Qiu");
context.put("site", "http://www.eiffelqiu.com");/* now render the template into a StringWriter */
StringWriter writer = new StringWriter();
t.merge(context, writer);/* show the World */
System.out.println(writer.toString());
}
}
---------------------------------------------
vm文件HeoolWorld.vm代码
---------------------------------------------
Hello $name! Welcome to $site world!
---------------------------------------------就是说找不到VM文件,为什么啊?org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'HelloWorld.vm'
at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:501)
at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:384)
at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:814)
at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:796)
at org.apache.velocity.app.VelocityEngine.getTemplate(VelocityEngine.java:512)
at HelloWorld.main(HelloWorld.java:11)
Exception in thread "main" Process terminated with exit code 1