我有一個web應用程序。我的控制器看起來是這樣的:錯誤的鏈接位置錯誤
@Controller
@RequestMapping(value = "/")
public class MainController {
@RequestMapping(method = RequestMethod.GET)
public String index() {
return "index";
}
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String add(ModelMap model, User user) {
userService.create(user);
model.addAttribute("message", "User successfully created.");
return "index";
}
}
而且我有這樣一種形式:
<form:form method="POST" action="/add" commandName="user">
的web.xml
<servlet>
<servlet-name>client</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>client</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/client-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
我的應用程序通過鏈接訪問:http://localhost:8080/Client
但是,當我提交表格提交至http://localhost:8080/add
應該是http://localhost:8080/Client/add
我想,我可以在每個鏈接之前使用${pageContext.request.contextPath}
,但有沒有其他方法?
讓我們看看'web.xml' – MariuszS
哦,我想我得到了你的觀點:) – qiGuar
尼斯:)回答補充:) – MariuszS