0

所有配置在代码中都是最正确的,但是资源错位正在发生

从“simple.jsp”请求/student3.htm发送到“web.xml”和“spring-servlet.xml”到SimpleUrlHandlerMapping请求/student3.htm被映射到bean id=class3它进入到multiactioncontroller有methodNameParameter有财产。

它连接到 PropertiesMethodNameResolver 类,其中它的属性是“映射”,将请求 /student3.htm 映射到 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.
4

1 回答 1

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.
于 2013-11-14T14:34:11.600 回答