1
回答
关于Velocity访问javabean传参问题,求教!!!
科大讯飞通用文字识别100000次/天免费使用。立即申请   

ToyTool.java 类

public class ToyTool {

	private String message = "Hello from ToyTool!";  
	  
    public String getMessage()  
    {  System.out.println("===========================================");
        return message;  
    }  
  
    public void setMessage(String m)  
    {  
        message = m;  
    }
    
    public void report(HttpServletRequest req){
    	System.out.println("=========================");
    	
    	System.out.println("===:"+req.getRequestURI());
    }
    
    public void reqs(String value){
    	System.out.println("=====调用成功了===="+value);
    }
  
    /** To test exception handling in templates. */  
    public boolean whine() {  
        throw new IllegalArgumentException();  
    }  
}
tools.xml 文件配置


<tools> 
    <data type="boolean" key="xhtml" value="true"/>  
    <data type="boolean" key="isSimple" value="true"/>  
    <data type="number" key="version" value="2.0"/>  
    <data key="foo">this is foo</data>  
    <data key="bar">this is bar.</data>
    <toolbox scope="request">
        <tool class="org.apache.velocity.tools.view.ViewContextTool"/>
        <tool class="org.apache.velocity.tools.generic.ResourceTool"/>
        <tool key="toytool" class="com.sps2h.view.ToyTool"/>
    </toolbox>
    <toolbox scope="session" locale="en_US">
    	<tool class="org.apache.velocity.tools.view.BrowserTool" languagesFilter="en"/>
    </toolbox>
    <toolbox scope="application">
    	<tool key="math" class="org.apache.velocity.tools.generic.MathTool"></tool>
    	<tool key="date" class="org.apache.velocity.tools.generic.DateTool"></tool>
    </toolbox>
</tools>
index.vm模板文件


<html>  
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<body>  
<br />
request value :$request.get("parameters").get("test")
<br />
$toytool.report($request) ##这个函数就调用不到
$toytool.reqs("===SUCCESS==") ##这个就可以正常调用
<br />
  
</body>  
</html>  


$toytool.report($request) ##这个函数就调用不到

信息:  Velocity  [debug] Null reference [template '/index.vm', line 7, column 1] : $toytool.report($request) cannot be resolved.


举报
村干部
发帖于5年前 1回/1K+阅
顶部