----------------------------------------------------------------------------------------------------
后来发现一个更为简便的方法
直接 super.getRequest().setAttribute("request", request);
汗死 脑袋被拍砖了
----------------------------------------------------------------------------------------------------
在etmvc+freemarker的环境下若想在ftl中得到当前页面的URL还是比较繁琐的(貌似使用etmvc后不能在ftl中使用request对象了)为此我只好些个Helpers了,
先建立个实体如下。
/* ***********************************************
* author : Anyhome
* email : ayhome@gmail.com
* function:
* @date 2009-12-14
* history: created by Anyhome
* ***********************************************/
/**
* 具体还可以自己再增减
*/
package org.anyhome.models;
import java.util.List;
/**
* @author Ayhome
*
*/
public class MyHelpers {
private String Url;
private String HostName;
private String Controller;
private String Action;
private String Method;
private String ContextPath;
private String Uri;
private List<String> Permission;
public void setUrl(String url) {
Url = url;
}
public String getUrl() {
return Url;
}
public void setHostName(String hostName) {
HostName = hostName;
}
public String getHostName() {
return HostName;
}
public void setController(String controller) {
Controller = controller;
}
public String getController() {
return Controller;
}
public void setAction(String action) {
Action = action;
}
public String getAction() {
return Action;
}
public void setMethod(String method) {
Method = method;
}
public String getMethod() {
return Method;
}
public void setContextPath(String contextPath) {
ContextPath = contextPath;
}
public String getContextPath() {
return ContextPath;
}
public void setUri(String uri) {
Uri = uri;
}
public String getUri() {
return Uri;
}
public void setPermission(List<String> permission) {
Permission = permission;
}
public List<String> getPermission() {
return Permission;
}
}
然后前置过滤器如下
protected boolean InitPages() throws ActiveRecordException{
MyHelpers Helpers = new MyHelpers();
Helpers.setAction(super.getActionName());
Helpers.setController(super.getControllerName());
Helpers.setUrl(super.request.getRequestURL().toString());
Helpers.setUri(super.request.getRequestURI());
Helpers.setContextPath(super.request.getContextPath());
//---
String ss = super.getControllerName().toLowerCase();
if (ss!="desktop"){
if (MyUserTicket!=null){
List<String> lst = new ArrayList<String>();
if (MyUserTicket.getU_Type()!=0){
lst = Permission.CheckAndPermiss(MyUserTicket.getUserID(),super.getControllerName());
}else{
for (String s:Permission.PopedomType().keySet()){
lst.add(s);
}
}
Helpers.setPermission(lst);
}
}
super.getRequest().setAttribute("Helpers", Helpers);
return true;
}
过滤器调用
@BeforeFilter(execute="Auth"),
FTL中的调用如
${Helpers.controller}