我有一个简单的弹簧应用程序,有很多关于这个问题的帖子,但我无法看到我错在哪里。我无法查看displayAllOrders.jsp,因为显示的是未找到的映射。 :(
请在下面找到我的web.xml映射:
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/pres.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>
请在下面找到pres.xml:
<!-- DispatcherServlet Context: defines this servlet's request-processing
infrastructure -->
<context:component-scan base-package="com.example.pres" />
<!-- Enables the Spring MVC @Controller programming model -->
<mvc:annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving
up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources
in the /WEB-INF/views directory -->
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<beans:bean id="validator"
class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
请在下面找到我的控制器(包:com.example.pres):
@Controller
public class OrderController {
private static final Logger logger = LoggerFactory
.getLogger(OrderController.class);
@Autowired
OrderService orderService;
@RequestMapping(method=RequestMethod.GET,value="/displayAllOrders")
public ModelAndView listPeople() {
logger.debug("Received request to list orders");
ModelAndView mav = new ModelAndView();
List<Order> order = orderService.getAllOrders();
logger.debug("Order Listing count = "+order.size());
mav.addObject("order",order);
mav.setViewName("displayAllOrders");
return mav;
}
请在页面home.jsp(Path:src \ main \ webapp \ WEB-INF \ views \ home.jsp)页面中找到href标签,该页面调用displayAllOrders.jsp(Path:src \ main \ webapp \ WEB -INF \视图\ displayAllOrders.jsp):
<a href=displayAllOrders> View order</a>
我可以显示主页,但是当我点击超链接displayAllOrders:
org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/project/displayAllOrders] in DispatcherServlet with name 'appServlet'
为什么我的映射不能用于displayAllOrders的任何想法?
提前致谢。
答案 0 :(得分:0)
您的网址映射适用于/displayAllOrders
,不适用于/project/displayAllOrders
,请更改控制器中的RequestMapping
并尝试。