在Spring2,5中找不到资源使用multiactioncontroller时出现404错误

时间:2013-11-13 18:37:07

标签: spring-mvc

所有配置在代码中都是最合适的,但资源的错位正在进行中

从“simple.jsp”请求/student3.htm发送到“web.xml”并发送到“spring-servlet.xml”到SimpleUrlHandlerMapping请求/student3.htm用bean id = class3映射它进入multiactioncontroller让methodNameParameter具有属性。

它连接到PropertiesMethodNameResolver类,其属性为“mappings”,将请求/student3.htm映射到“save”命名方法,在multiactioncontroller扩展类中有“Multi.java”类。 然后save方法通过/WEB-INF/jsp/multi.jsp中的InternalResourceViewResolver返回ModelAndView作为multi.jsp的视图名称“multi”,用于消息multiactionsuccess。

               HTTP Status 404 - /student3.htm

            --------------------------------------------------------------------------------

            type Status report

            message /student3.htm

            description The requested resource (/student3.htm) is not available.


            --------------------------------------------------------------------------------

            Apache Tomcat/6.0.35


           In console

            INFO: The APR based Apache Tomcat Native library which allows optimal performance in                   production environments was not found on the java.library.path: C:\Program Files  (x86)\Java\jdk1.6.0_12\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files    (x86)\Java\jdk1.6.0_12\bin
            WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property                              'source' to 'org.eclipse.jst.jee.server:springmvc2.56' did not find a matching property.


           no error message is found and only warning message.please found out the 404 error                                                                             found  in Broswer.








            In web.xml
            <?xml version="1.0" encoding="UTF-8"?>
             <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"                                                                             xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web- app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">


           <servlet>
           <servlet-name>spring</servlet-name>
           <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
           <load-on-startup>1</load-on-startup>
           </servlet>
           <servlet-mapping>
           <servlet-name>spring</servlet-name>
           <url-pattern>*.htm</url-pattern>
           </servlet-mapping>
           </web-app>


            in spring-servlet.xml


             <?xml version="1.0" encoding="UTF-8"?>
             <beans xmlns="http://www.springframework.org/schema/beans"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns:util="http://www.springframework.org/schema/util"
              xsi:schemaLocation="
              http://www.springframework.org/schema/beans                            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
              http://www.springframework.org/schema/util                  http://www.springframework.org/schema/util/spring-util-2.5.xsd">

          <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
          <property name="mappings">
          <value>


          /student3.htm=class3
          /student4.htm=class3
          /student5.htm=class3
          /student6.htm=class3

          </value>
          </property>
          </bean>

          <bean  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="class3" class="com.spring.controller.Multi">
            <property name="methodNameResolver" >
             <bean                              class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
              <property name="mappings" >
              <value>
                   /student3.htm=save
                   /student4.htm=update
                   /student5.htm=delete
                   /student6.htm=select
               </value>
              </property>
         </bean> 
         </property>

          </bean>

          </beans>

          In WebContent simple.jsp

          <%@taglib prefix="c" uri="http://www.springframework.org/tags" %>
          <%@taglib prefix="f" uri="http://www.springframework.org/tags/form" %>


           <a href="/student3.htm" >save</a>
           <a href="/student4.htm" >update</a>
           <a href="/student5.htm" >delete</a>
           <a href="/student6.htm" >select</a>


          In com.spring.controller package Multi.java is controller Class

          package com.spring.controller;

          import javax.servlet.http.HttpServletRequest;
          import javax.servlet.http.HttpServletResponse;

          import org.springframework.web.servlet.ModelAndView;
          import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

           public class Multi extends MultiActionController
           {


              protected ModelAndView save(HttpServletRequest arg0,
        HttpServletResponse arg1) throws Exception 
        {

                    ModelAndView mav = new ModelAndView();
                    mav.setViewName("multi1");

                    return mav;
                 }

                protected ModelAndView update(HttpServletRequest arg0,
        HttpServletResponse arg1) throws Exception 
        {

                 ModelAndView mav = new ModelAndView();
                 mav.setViewName("multi1");

                  return mav;
                     }

                    protected ModelAndView select(HttpServletRequest arg0,
            HttpServletResponse arg1) throws Exception 
            {

                 ModelAndView mav = new ModelAndView();
                 mav.setViewName("multi1");

                 return mav;
                     }

                     protected ModelAndView delete(HttpServletRequest arg0,
             HttpServletResponse arg1) throws Exception 
             {

                  ModelAndView mav = new ModelAndView();
                  mav.setViewName("multi1");

                  return mav;
                      }
                  }

                 In WEB-INF/jsp folder "multi.jsp" is present

                 multiaction success.

1 个答案:

答案 0 :(得分:0)

     method - access specifies should be "public" by userdefined methods
            -returntype should be "ModelAndView,Map,void"

     In the above code retifications are

     In WebContent simple.jsp

       <a href="student3.htm" >save</a>
       <a href="student4.htm" >update</a>
       <a href="student5.htm" >delete</a>
       <a href="student6.htm" >select</a>

      In com.spring.controller package Multi.java is controller Class

      method access specifies should be public
      change multi1 to multi as successView in all methods

      After editing the code done this  is successfully executed.