哪位大侠整过struts2整合velocity啊?求指点??

爱coding 发布于 2012/04/10 15:58
阅读 961
收藏 0

这是我的struts.xml文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
    "http://struts.apache.org/dtds/struts-2.1.7.dtd">
<struts>
 <constant name="struts.devMode" value="false"/>
 <constant name="struts.configuration.xml.reload" value="true"/>
 <package namespace="/" name="" extends="struts-default">
   <action name="velocity" class="com.sanjiawu.action.VelocityAction">
    <result name="success">HelloVelocity.vm</result>
   </action>
 </package>
</struts>

web.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 <filter>
  <filter-name>Struts2</filter-name>
  <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>Struts2</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 
 
 <servlet>
   <servlet-name>velocity</servlet-name>
   <servlet-class>
           org.apache.velocity.tools.view.servlet.VelocityViewServlet
   </servlet-class>                                           
   <init-param>
     <param-name>org.apache.velocity.toolbox</param-name>
     <param-value>/WEB-INF/toolbox.xml</param-value>     
  </init-param>              
   <init-param>
        <param-name> org.apache.velocity.properties </param-name>
        <param-value> /WEB-INF/velocity.properties </param-value>
     </init-param>
  <load-on-startup>10</load-on-startup>
 </servlet>
 
 <servlet-mapping>
   <servlet-name>velocity</servlet-name>
   <url-pattern>*.vm</url-pattern>     
 </servlet-mapping> 
</web-app>

怎么找不到 The requested resource (/HelloVelocity.vm) is not available.抱这种错呢??
加载中
0
红薯
红薯
velocity.properties 这里定义了 velocity 去哪里加载 vm 模板文件,你怎么写的?
爱coding
爱coding
再问一下,<result name="success">HelloVelocity.jsp</result>这能写jsp文件吗?只能写.vm文件吗?
0
爱coding
爱coding

velocity.properties文件

input.encoding=UTF-8
output.encoding=UTF-8
resource.loader = file
file.resource.loader.path=D\:\\myworkspace\\struts\\WebRoot
webapp.root.url=http://192.168.12.48:8080

webapp.template.path=D\:\\myworkspace\\struts\\WebRoot

是这样写的,

 

0
爱coding
爱coding

好了,老大,是把这句话resource.loader = file删掉就ok了,非常感谢!!

返回顶部
顶部