当我访问localhost时:8080 / 主页 - 我得到:
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"/>
tiles.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>
ErrorController
@Controller
public class ErrorController {
@RequestMapping("/403")
public String error403() {
return "403";
}
@RequestMapping("/404")
public String error404() {
return "404";
}
}
UserController中
@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
日志中感兴趣的时刻:
将映射的网址路径[/ homepage.html ]导入处理程序“userController” 我添加了,并在控制器中删除那些@RequestMapping,但它仍然存在
我在Idea 12.0.4中工作
答案 0 :(得分:2)
问题出在缓存/ IDE中。
部署项目时不会更新类文件。
我第一次遇到这样的麻烦。只需重新启动IDE并清理tomcat webapps文件夹(从此处删除我的项目文件)。
现在一切都按预期工作了。