I am trying to log run time data in spring using AOP. I am able to log the static messages. But my problem is I have to log the input values given by the user(Eg.Name) and my log message should be as” Siva has logged in” if the user enters ‘siva’ as username in the form.
I have a jsp form with text boxes for getting username , bean class which has setter and getter for the username, a controller class and an aspect class.
My controller class is:
@RequestMapping("/login.htm")
public ModelAndView success(String name){
}
My Aspect class is:
@After("execution(* com.controller.MyController.success(String))&&args(name)")
public void After(){
System.out.println("after method");
}
I am not sure how to get the username in the controller method. I am totally blind. I searched and tried many possibilities but nothing worked out. Any help is appreciated….Thanks in advance…
To get the username parameter in your controller method you just need to annotate the “name” argument with @RequestParam. e.g.:
And to get the name in your after advice, just change the after method’s signature to accept “name” string:
Hope it solves the issues.