问题描述:

All the configurations are allmostproper in code but misplacement of resources is going on

From "simple.jsp" the request /student3.htm is sending to " web.xml" and to "spring-servlet.xml" to SimpleUrlHandlerMapping request /student3.htm is mapped with bean id=class3 it enters to multiactioncontroller having methodNameParameter has property.

And it is wired to PropertiesMethodNameResolver class where its property is "mappings" maps the request /student3.htm to "save" named method in multiactioncontroller extended class there is "Multi.java" class.

Then save method returns ModelAndView as view name "multi" for multi.jsp through InternalResourceViewResolver in /WEB-INF/jsp/multi.jsp for message 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.

网友答案:
     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.
相关阅读:
Top