当我访问 localhost:8080/ home - 我得到:
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/home] in DispatcherServlet with name 'appServlet'
当我访问 localhost:8080/ 或 localhost:8080/index 时看起来一切正常。
为什么一条路径有效,而另一条路径无效?
还有一件事,让我感到困惑:localhost:8080/homepage.html - 将我的主视图返回给我。
所以我的项目在这里:https ://github.com/IRus/jMusic
我的web.xml
<!-- Base servlet handles all requests to the application. -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
servlet-context.xml - 我使用瓷砖
<annotation-driven/>
<resources mapping="/resources/**" location="/resources/"/>
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/"/>
<beans:property name="suffix" value=".jsp"/>
<beans:property name="order" value="1" />
</beans:bean>
<beans:import resource="controllers.xml"/>
<beans:import resource="tiles.xml" />
<beans:import resource="i18n.xml"/>
<beans:import resource="themes.xml"/>
瓷砖.xml
<bean id="tilesviewResolver" class="org.springframework.web.servlet.view.tiles2.TilesViewResolver">
<property name="order" value="0"/>
</bean>
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/views/tiles-definitions.xml</value>
</list>
</property>
</bean>
错误控制器
@Controller
public class ErrorController {
@RequestMapping("/403")
public String error403() {
return "403";
}
@RequestMapping("/404")
public String error404() {
return "404";
}
}
用户控制器
@Controller
public class UserController {
@Autowired
private UserService userService;
@RequestMapping("/")
public String index() {
return "redirect:/index";
}
@RequestMapping("/home")
public String home() {
return "home";
}
@RequestMapping("/login")
public String login() {
return "login";
}
@RequestMapping("/index")
public String listUsers(Map<String, Object> map) {
map.put("user", new User());
map.put("userList", userService.listUser());
return "user";
}
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String addUser(@ModelAttribute("user") User user,
BindingResult result) {
userService.addUser(user);
return "redirect:/index";
}
@RequestMapping("/delete/{idUser}")
public String deleteUser(@PathVariable("idUser") Long idUser) {
userService.removeUser(idUser);
return "redirect:/index";
}
}
此处记录: https ://gist.github.com/IRus/2ac97c66070001247011
日志中感兴趣的时刻:
将URL 路径 [/ homepage.html ] 映射到我添加的处理程序 'userController' 中,然后删除控制器中的 @RequestMapping,但它仍然存在
我在 Idea 12.0.4 工作