veloctiy vm 文件找不到

luluback 发布于 2012/03/21 12:49
阅读 487
收藏 0
我在web工程里面以下面这种方式去处理vm请求,找不到该vm资源,vm文件web 根目录,WEB-INF以及类路径下均找不到,难道我一定要通过继承VeloctiyServlet来处理吗
private void doGet(HttpServletRequest req, HttpServletResponse resp, boolean isPost) {
        String uri = req.getRequestURI();
        try {
            Method method = getMethod(uri);
            BaseAction action = getAction(uri);
            if (action!=null && method!=null) {
                String page = (String) method.invoke(action, new Object[]{req});
                if (page.indexOf(".vm")>0) {
                    VelocityEngine ve = new VelocityEngine();
                    ve.init();
                    Template t = ve.getTemplate(page);
                    ve.addProperty("tools.view.servlet.layout.directory", "/layout");
                    VelocityContext context = new VelocityContext();
                    context.put("hello", "hello,veloctiy");
                    PrintWriter out = new PrintWriter(resp.getOutputStream());
                    t.merge(context, out);
                    out.flush();
                    out.close();
                } else {
                    resp.sendRedirect(page);
                }               
            }           
        } catch (IllegalArgumentException e) {
        } catch (IllegalAccessException e) {
        } catch (InvocationTargetException e) {
        } catch (IOException e) {
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource

加载中
0
luluback
luluback
红薯 回答于 2011-01-10 22:36 (1年前)

resource.loader = webapp

在以前的帖子里面找到了答案,多谢红薯

返回顶部
顶部