我正在使用 Spring MVC3.2 并且我有一个注册表单(http://my-server.com:8080/tracks/apks)。用户将其发布到服务器,验证失败时服务器将返回错误消息。但是我从服务器收到错误消息,URL 与我想要的不同。这是我的代码:
Web.xml
<servlet-mapping>
<servlet-name>tracks</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
applicationContext.xml
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
@Controller
@RequestMapping("/apks")
public class ApkController {
@RequestMapping()
public ModelAndView index() {
Map<String, Object> modelMap = new HashMap<String, Object>();
modelMap.put("menus", AdminService.getMenus("apks"));
return new ModelAndView("apks", "model", modelMap);
}
@RequestMapping(value = "/insert", method = RequestMethod.POST)
public ModelAndView uploadApk(ApkInfo apkInfo, BindingResult bindingResult) {
Map<String, Object> modelMap = new HashMap<String, Object>();
modelMap.put("menus", AdminService.getMenus("apks"));
if (!fileExists(apk.getFileName())){
modelMap.put("message", message);
}
//Do something
return new ModelAndView("apks", "model", modelMap);
}
调用 uploadApk 后,我期望http://my-server.com:8080/tracks/apks但返回的 URL 是http://my-server.com:8080/tracks/apks/insert。
我该怎么做才能修复它?
提前致谢。