【发布时间】:2015-09-05 11:25:18
【问题描述】:
我编写了一个带有多个控制器的 Spring MVC 应用程序。
在 JSP 上,我在表单上有 action:
<form id="createTableForm" method="post" name="createTable" action="${pageContext.request.contextPath}/saveTable" >
同样的动作映射到Controller中的一个方法:
@Controller
public class TableController implements TableConstants {
@RequestMapping(value="/saveTable")
public String saveTable(HttpServletRequest request,RedirectAttributes redirectAttributes) {
//...
}
}
在我的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>
我是否需要在web.xml 文件或WebAppConfig 类中包含到该特定控制器的URL 映射?
我有WebAppConfig 用@Configuration、@ComponentScan 和@EnableWebMVC 注释。它有以下几种方法:
public UrlBasedViewResolver setupViewResolver() {
}
public MessageSource messageSource() {
}
public void addResourceHandlers(ResourceHandlerRegistry registry) {
}
public CommonsMultipartResolver multipartResolver() {
}
请指教。
【问题讨论】:
-
所以你想实现那个特定的控制器也有自己的 URL 映射?
-
我想知道正确的方法,到目前为止,我的 Controller 类只是用 @Controller 注释进行了注释。那么我们是否应该提供到 Controller 类的 URL 映射并将该映射附加到 JSP 中的操作以及 RequestMapping URL
-
发布您的 servlet-config.xml
-
向控制器添加RequestMapping注解。
-
不清楚你在问什么。您是否希望您的控制器有一个 URL,以便您的请求 URL /saveTable 改为 /foo/saveTable?
标签: java xml jsp spring-mvc spring-4