项目场景:
学习maven高级,配置完web.xml和controller,运行tomcat,报错
问题描述:
HTTP状态 404 - 未找到,源服务器未能找到目标资源的表示或者是不愿公开一个已经存在的资源表示。
ItemController文件:
@Controller
@RequestMapping("/item")
public class ItemController {
@Autowired
private ItemService itemService;
@RequestMapping("/showItem/{id}")
public String findById(@PathVariable("id") int id, Model model){
Item item = itemService.findById(id);
model.addAttribute("item",item);
return "item";
}
}
springmvc.xml:
<!--配置视图解析器-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp"/>
<property name="suffix" value=".jsp"/>
</bean>
<!--配置springmvc的前端控制器-->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--指定springmvc的配置文件-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
原因分析:
/WEB-INF/jsp掉了一个斜杠
解决方案:
加一个斜杠