2014-05-01 72 views
0

我想從Request變量中獲取參數後變爲「」而不是null。AspectJ getParameter()

import javax.servlet.ServletRequest; 

public aspect GetParameter { 

    pointcut getParam(ServletRequest req, String s): 
     target(req) && args(s) && 
     execution(String javax.servlet.ServletRequest.getParameter(String)); 

    String around(ServletRequest req, String s): getParam(req, s) { 
     String result = req.getParameter(s); 
     if (result == null) { 
      return ""; 
     } 
     return result;  
} 

在管線String around(ServletRequest req, String s): getParam(req, s) { Eclipse中顯示此mesage:在aspects.GetParameterOrAttribute定義建議尚未應用於 [Xlint:adviceDidNotMatch]

回答

1

變更執行調用,和到的ServletRequest ServletRequest中+。應該捕獲所有對ServletRequest及其子類的getParameter調用。

+0

它的工作原理,非常感謝! – sard