• Write a java class extending “MultiActionController”.
Extend MultiActionController in SessionController class and group multiple action methods related to session. Eg: login and logout.
package com.jb.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction. MultiActionController;
public class SessionController extends MultiActionController {
public ModelAndView login(HttpServletRequest request,
HttpServletResponse response) throws Exception {
String message = “Login method called”;
System.out.println(message);
return new ModelAndView("user", "message", message);
}
public ModelAndView logout(HttpServletRequest request,
HttpServletResponse response) throws Exception {
String message = “Logout method called”;
System.out.println(message);
return new ModelAndView("user", "message", message);
}
}
• Configure the controller in spring bean file.
Here is a spring bean configuration file to map a request url to MultiActionController. An asterisk character can be used to define request url.
Characters toning asterisk will be considered as method name in SessionController.
• Invoking login and logout action methods from jsp.
Login and Logout methods can be invoked by posting request on following url from jsp.
Login Logout
No comments:
Post a Comment