会springmvc的大神看看org.springframework.web.servlet.DispatcherServlet noHandlerFound
本人用springmvc开发遇到了一个问题,用google和百度都搜不到与自己问题一致的答案。将问题贴出来求助各位路易做图神。web.xml主要的配置
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
</web-app>
applicationContext-mvc.xml主要的配置
<mvc:annotation-driven />
<context:component-scan base-package="com.*.*.web.controller" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" />
</beans>
这是我的项目目录(由于上传不了图只好用文字描述下):
forklift(项目名)
com.bb.demo.dao(包名)
BookDao.java
ForkliftInfoDao.java
com.bb.demo.dao.impl
BookImpl.java
ForkliftInfoDaoImpl.java
com.bb.demo.model
book.java
ForkliftInfo.java
com.bb.demo.web.controller
BookController.java
ForkliftInfoController.java
然后是book和forkliftInfo的代码几乎是一样的,可是访问页面的时候book的增删改查都没有问题,forkliftInfo访问就出现:org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/cc/forkliftInfo/forkInlist.do] in DispatcherServlet with name 'springmvc'
我发现服务器启动的时候book的add,list,delete,update加载了两次(如下所示),而forkliftInfo访问就出现上面的问题
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping registerHandlerMethod
INFO: Mapped "{[/book/add],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.bb.demo.web.controller.BookController.add(com.bb.demo.model.Book)
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping registerHandlerMethod
INFO: Mapped "{[/book/list],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.util.Map<java.lang.String, java.lang.Object> com.bb.demo.web.controller.BookController.list(int,int)
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping registerHandlerMethod
INFO: Mapped "{[/book/delete],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.bb.demo.web.controller.BookController.delete(int[])
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping registerHandlerMethod
INFO: Mapped "{[/book/update],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.bb.demo.web.controller.BookController.update(com.bb.demo.model.Book)
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping registerHandlerMethod
INFO: Mapped "{[/book/add],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.bb.demo.web.controller.BookController.add(com.bb.demo.model.Book)
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping registerHandlerMethod
INFO: Mapped "{[/book/list],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.util.Map<java.lang.String, java.lang.Object> com.bb.demo.web.controller.BookController.list(int,int)
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping registerHandlerMethod
INFO: Mapped "{[/book/delete],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.bb.demo.web.controller.BookController.delete(int[])
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping registerHandlerMethod
INFO: Mapped "{[/book/update],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.bb.demo.web.controller.BookController.update(com.bb.demo.model.Book)
最后,我的访问方式是基于注解的方式,下面是bookController.java的部分代码
@Controller("bookController")
public class BookController extends BaseController {
// 书籍实体
private BookDao bookDao;: String
@RequestMapping(value = "/book/add", method = RequestMethod.POST)
public @ResponseBody
String add(Book book) {
if(book!=null){
bookDao.save(book);
return "true";
}else{
return "false";
}
}
@RequestMapping(value = "/book/list", method = RequestMethod.GET)
public @ResponseBody
Map<String, Object> list(int start, int limit) {
List<Book> list = bookDao.load(start, limit);
long count = bookDao.getCount();
Map<String, Object> map = new HashMap<String, Object>();
map.put("list", list);
map.put("count", count);
return map;
}
@RequestMapping(value = "/book/delete", method = RequestMethod.GET)
public @ResponseBody
String delete(int[] id) {
bookDao.batchDel(id);
return "true";
}
问题描述的有点长,希望能有人遇到过和我一样的问题,求解释啊。。。 --------------------编程问答-------------------- 又发一遍?
noHandlerFound 说明你的Controller没找到。
你再仔细看一下forkliftInfo部分的@RequestMapping("。。。")
补充:Java , Web 开发