I have written a Spring MVC application with multiple controllers.
On the JSP, I have the action
on the form:
<form id="createTableForm" method="post" name="createTable" action="${pageContext.request.contextPath}/saveTable" >
and the same action is mapped to a method in the Controller:
@Controller
public class TableController implements TableConstants {
@RequestMapping(value="/saveTable")
public String saveTable(HttpServletRequest request,RedirectAttributes redirectAttributes) {
//...
}
}
And in my web.xml
:
<context-param>
<description>Context name of the Application</description>
<param-name>contextName</param-name>
<param-value>W****</param-value>
</context-param>
<context-param>
<description>Database used for</description>
<param-name>databaseName</param-name>
<param-value>w*****</param-value>
</context-param>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>FilterChainProxy</filter-name>
<filter-class>com.abc.w****.configuration.FilterChainProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>FilterChainProxy</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>1</session-timeout>
</session-config>
<jsp-config>
<taglib>
<taglib-uri>http://displaytag.sf.net</taglib-uri>
<taglib-location>/WEB-INF/tld/displaytag.tld</taglib-location>
</taglib>
</jsp-config>
Do I need to include the URL mapping to that particular Controller in the web.xml
file or in the WebAppConfig
class?
I have the WebAppConfig
annotated with @Configuration, @ComponentScan and @EnableWebMVC. It has the following methods:
public UrlBasedViewResolver setupViewResolver() {
}
public MessageSource messageSource() {
}
public void addResourceHandlers(ResourceHandlerRegistry registry) {
}
public CommonsMultipartResolver multipartResolver() {
}
Please advise.
The ASP.NET MVC framework uses the ASP.NET routing engine, which provides flexibility for mapping URLs to controller classes. You can define routing rules that the ASP.NET MVC framework uses in order to evaluate incoming URLs and to select the appropriate controller.
RequestMapping annotation is used to map web requests onto specific handler classes and/or handler methods. @RequestMapping can be applied to the controller class as well as methods.
Quite right, you can only use @RequestMapping on @Controller annotated classes. From the javadoc of the @Controller class: Base Controller interface, representing a component that receives HttpServletRequest and HttpServletResponse instances just like a HttpServlet [...]
The @RequestMapping
annotation could be applied to the controller class. In this case all the methods in this class will derive the defaults from the class annotation and the implementation could override it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With