最近在学习ssm整合,就在练手方案中遇到了一个action访问404的问题。这是我的springmvxc.xml的配置:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.2.xsd 
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">
<!-- 通过spring组建扫描 -->
<context:component-scan base-package="mz.ssm.controller"/>

<!-- 通过annotation-driven可以替代下边的处理器映射器和适配器 -->
<!--  <mvc:annotation-driven conversion-service="conversionService">
</mvc:annotation-driven>-->



<!-- 注解处理器映射器 -->
<bean
class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>

<!-- 注解适配器 -->
<bean
class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" /> <!-- 配置视图解析器 要求将jstl的包加到classpath -->
<!-- ViewResolver -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" /> </bean>
</beans>这是web.xml的配置<display-name>ssmproject</display-name>



<!-- 配置spring容器监听器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/spring/applicationContext-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- 前端控制器 -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 加载springmvc配置 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<!-- 配置文件的地址 如果不配置contextConfigLocation, 默认查找的配置文件名称classpath下的:servlet名称+"-serlvet.xml"即:springmvc-serlvet.xml -->
<param-value>classpath:spring/springmvc.xml</param-value>
</init-param> </servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<!-- 可以配置/ ,此工程 所有请求全部由springmvc解析,此种方式可以实现 RESTful方式,需要特殊处理对静态文件的解析不能由springmvc解析 
可以配置*.do或*.action,所有请求的url扩展名为.do或.action由springmvc解析,此种方法常用 不可以/*,如果配置/*,返回jsp也由springmvc解析,这是不对的。 -->
<url-pattern>*.action</url-pattern>
</servlet-mapping>
</web-app>这是我controller的部分:@Controller
public class ItemsController {
//注入service
private ItemsService itemsService;

@RequestMapping("/queryItems")
public ModelAndView queryItems( ) throws Exception{
List<ItemsCustom> itemsList=itemsService.findItemsList(null);

ModelAndView modelAndView=new ModelAndView();
modelAndView.addObject("itemsList",itemsList);
//指定逻辑视图名
modelAndView.setViewName("itemsList");
return modelAndView;
}
}
这是我的程序结构
我想通过访问queryitems.action访问webweb-inf/jsp/下的itemslist.jsp却总是提示开头所提到的那个页面。
不知道什么情况什么问题。

解决方案 »

  1.   

    你aciton进来了没我都怀疑..
      

  2.   

    @RequestMapping("/queryItems")
    在这加个.action试试
      

  3.   

    我是小白,怎么看action有没有进来,后台没有报错啊。页面信息就是上图的。
      

  4.   

    加了也没用应该是没进action的,我给你贴一个我之前测的例子吧@Controller
    @RequestMapping("/book.do")
    public class BookController {
    private BookService bookService; @RequestMapping(params = "method=add")
    public String add(Book book) {
    System.out.println("bookname:" + book.getName());
    System.out.println("author:" + book.getAuthor());
    bookService.add(book);
    return "success";
    } @RequestMapping(params = "method=update")
    public String update(Book book) {
    bookService.update(book);
    return "success";
    } public BookService getBookService() {
    return bookService;
    } @Resource
    public void setBookService(BookService bookService) {
    this.bookService = bookService;
    }}
    前台访问<form method="post"
    action="<%=request.getContextPath()%>/book.do?method=add">
    bookname:<input type="text" name="name" id="name"> author:<input
    type="text" name="author" id="author"> <input type="submit"
    value="Add">
    </form>
      

  5.   

    加了也没用应该是没进action的,我给你贴一个我之前测的例子吧@Controller
    @RequestMapping("/book.do")
    public class BookController {
    private BookService bookService; @RequestMapping(params = "method=add")
    public String add(Book book) {
    System.out.println("bookname:" + book.getName());
    System.out.println("author:" + book.getAuthor());
    bookService.add(book);
    return "success";
    } @RequestMapping(params = "method=update")
    public String update(Book book) {
    bookService.update(book);
    return "success";
    } public BookService getBookService() {
    return bookService;
    } @Resource
    public void setBookService(BookService bookService) {
    this.bookService = bookService;
    }}
    前台访问<form method="post"
    action="<%=request.getContextPath()%>/book.do?method=add">
    bookname:<input type="text" name="name" id="name"> author:<input
    type="text" name="author" id="author"> <input type="submit"
    value="Add">
    </form>
    你好请问怎么判断有没有进action?
      

  6.   

    加了也没用应该是没进action的,我给你贴一个我之前测的例子吧@Controller
    @RequestMapping("/book.do")
    public class BookController {
    private BookService bookService; @RequestMapping(params = "method=add")
    public String add(Book book) {
    System.out.println("bookname:" + book.getName());
    System.out.println("author:" + book.getAuthor());
    bookService.add(book);
    return "success";
    } @RequestMapping(params = "method=update")
    public String update(Book book) {
    bookService.update(book);
    return "success";
    } public BookService getBookService() {
    return bookService;
    } @Resource
    public void setBookService(BookService bookService) {
    this.bookService = bookService;
    }}
    前台访问<form method="post"
    action="<%=request.getContextPath()%>/book.do?method=add">
    bookname:<input type="text" name="name" id="name"> author:<input
    type="text" name="author" id="author"> <input type="submit"
    value="Add">
    </form>
    你好请问怎么判断有没有进action?
    在你要执行的那个方法里打印一句话,或者打个断点,然后执行一下就能看出来
      

  7.   

    我是小白,怎么看action有没有进来,后台没有报错啊。页面信息就是上图的。
    你可以在后台要进的方法打个断点看看有没有跳进来,另外把你的页面代码提上来,看看是不是提交的路径写的有问题也说不准的
      

  8.   

    我是小白,怎么看action有没有进来,后台没有报错啊。页面信息就是上图的。
    你可以在后台要进的方法打个断点看看有没有跳进来,另外把你的页面代码提上来,看看是不是提交的路径写的有问题也说不准的
    这是我的访问路径。
      

  9.   

    我是小白,怎么看action有没有进来,后台没有报错啊。页面信息就是上图的。
    你可以在后台要进的方法打个断点看看有没有跳进来,另外把你的页面代码提上来,看看是不是提交的路径写的有问题也说不准的
    这是我的访问路径。
    localhost:8080 这个是不是漏了?
      

  10.   

    我是小白,怎么看action有没有进来,后台没有报错啊。页面信息就是上图的。
    你可以在后台要进的方法打个断点看看有没有跳进来,另外把你的页面代码提上来,看看是不是提交的路径写的有问题也说不准的
    这是我的访问路径。
    localhost:8080 这个是不是漏了?
    有的。没有漏。
      

  11.   

    我是小白,怎么看action有没有进来,后台没有报错啊。页面信息就是上图的。
    你可以在后台要进的方法打个断点看看有没有跳进来,另外把你的页面代码提上来,看看是不是提交的路径写的有问题也说不准的
    这是我的访问路径。
    localhost:8080 这个是不是漏了?
    有的。没有漏。
    测试代码发我一份?
      

  12.   

    请求的action是 项目域名/action的形式。前缀必须完整,不然请求不到。
      

  13.   

    request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath() + /  你的action,试试
      

  14.   

    你这运行除了404以外,没有报其它错吗?
    我看你controller的service都没有注入, 
    把@Autowired加上试试 //注入service
        @Autowired
        private ItemsService itemsService;
      

  15.   

    这些网上找一个demo,都有相应的教程,把教程上的运行了,理解了你就可以试着搞了
      

  16.   

    springMVC的控制器中有控制器路径与方法路径
    两个@ReauestMappering("/xxx")
    一个加在类上,另一个加在方法上
      

  17.   

    注解处理器映射器和适配器被你注释掉了,action映射不成功,所以报404错误!!!
      

  18.   

    <!--     <mvc:annotation-driven conversion-service="conversionService">
        </mvc:annotation-driven>-->
      

  19.   

    你的路径没对 ssmproject这个映射到哪里的?你应该将它映射到你的controller
      

  20.   

    <param-value>/WEB-INF/classes/spring/applicationContext-*.xml</param-value>   
     不是应该在 web-inf 目录下创建 spring目录的吗??
      

  21.   

    哦 是先创建 classes目录 再创建spring目录