0

Ok i got the way of using multiple controllers as i want as-

inedx.jsp

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <a href="hello/One.html">Say Hello One</a><br> <a href="hello/Two.html">Say Hello Two</a><br> <a href="hi/One.html">Say Hi One</a> </body> 

dispatcher-servel.xml

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" etc... <mvc:annotation-driven/> <context:component-scan base-package="com.fastek.crm3" /> <mvc:resources mapping="/resources/**" location="/resources/"/> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> </beans> 

Here the two controllers and their methods are as-

@Controller @RequestMapping("/hello") public class HelloController { @RequestMapping(value="/One") public ModelAndView sayHello(@ModelAttribute("stdUser") StdUsers stdUser,BindingResult result) { System.out.println("/////called from one-----------"); String mess = "hello from one"; StdCheckAccessV chk = new StdCheckAccessV(); chk.setDFlag(1); stdUser.setChkAccessV(chk); return new ModelAndView(Screens.User, "message", mess); } @RequestMapping(value="/Two") public ModelAndView sayHelloTwo(@ModelAttribute("stdUser") StdUsers stdUser,BindingResult result) { System.out.println("/////called from two-----------"); String mess = "hello from two"; StdCheckAccessV chk = new StdCheckAccessV(); chk.setDFlag(1); stdUser.setChkAccessV(chk); return new ModelAndView(Screens.User, "message", mess); } } 

and

@Controller @RequestMapping("/hi") public class OtherController { @RequestMapping(value="/One") public ModelAndView sayHiOne(@ModelAttribute("stdUser") StdUsers stdUser,BindingResult result) { System.out.println("/////called from hi one-----------"); String mess = "hi from one"; StdCheckAccessV chk = new StdCheckAccessV(); chk.setDFlag(1); stdUser.setChkAccessV(chk); return new ModelAndView(Screens.User, "message", mess); } } 

Everything is working fine and as i understood from this example is appropriate Controller and method will be executed for related URL. As i am new born for Spring i just want to know that is there any way to controlling the Controller's call through dispatcher-servlet?I mean what i have to write in dispatcher-servlet to achieve that. Please help.

3
  • 2
    What exactly do you mean by controlling the Controller's call through dispatcher-servlet? Commented Dec 19, 2013 at 19:28
  • Do you mean authorization? Commented Dec 19, 2013 at 20:54
  • @Sotirios Delimanolis, sir as in present situation the the Controller and its method is being identified by the url pattern send by .jsp page, first it finds the appropriate controller /hello and then related methods i.e. /sayHello or /sayHelloTwo. So is there any way to do it in dispatcher-servlet , i mean how could i decide in dispatcher servlet that this url should use this controller and that url should use another controller and their method? Commented Dec 20, 2013 at 5:30

1 Answer 1

1

Spring mvc uses the Front Controller pattern. This means that all request are handled by the front controller(the Dispatcher Servlet) and then are passed to you application to process them(the controllers you wrote). You don't have to interact with the Dispatcher Servlet. It's purpose is just to route the requests to your controllers. You controll the controllers call with the RequestMapping. enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.