【问题标题】:MultiActionController no longer receiving requests?MultiActionController 不再接收请求?
【发布时间】:2010-03-16 15:51:34
【问题描述】:

我试图更改我的控制器,突然之间,我似乎不再收到任何请求(尝试访问 servlet 映射的 URL 时出现 404)。我确定我的web.xmlapp-servlet.xml 坏了,但我就是不知道在哪里。我可以从 tomcat (http://IP/app/index.jsp) 访问 index.jsp,但我的 servlet 映射无法正常工作。

帮助?

web.xml:

<!DOCTYPE web-app 
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 
    "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app version = "2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>

<servlet>
    <servlet-name>app</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>

<servet-mapping>
    <servlet-name>app</servlet-name>
    <url-pattern>/myRequest</url-pattern>
</servet-mapping>

app-servlet.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
     <bean id = "MyController" class = "com.stefankendall.MyController" ></bean>

     <bean id="urlMappingDeployment" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
      <property name="mappings">
         <props>
             <prop key="/myRequest">MyController</prop>
         </props>
      </property>
   </bean>

</beans>

【问题讨论】:

  • 请提供更多详细信息,据我所知,您没有页面,这会给您一个 404。您没有指定欢迎页面,并且您仅将该控制器映射到名称“/myRequest ",只有那个特定的 URL 甚至会被发送到 app-servlet.xml。当您访问 yoursite/myRequest 时,您想完成什么?
  • 这是一个简单的网络服务。我只是在测试一个概念。我只需要传递那个 URL,是的。

标签: spring spring-mvc controller tomcat6


【解决方案1】:

首先,您的控制器映射应该看起来更像这样,但是您的 URL“模式”看起来也很可疑,模式很少是静态字符串,但如果您想要的是映射的 URL“/myRequest”对于您的控制器,您只需要以下内容:

<bean name = "/myRequest" class = "com.stefankendall.MyController" ></bean>

【讨论】:

    【解决方案2】:

    &lt;url-pattern&gt;/myRequest&lt;/url-pattern&gt; 应该是&lt;url-pattern&gt;/myRequest/*&lt;/url-pattern&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-16
      • 1970-01-01
      • 2011-04-07
      • 1970-01-01
      • 2013-11-15
      • 1970-01-01
      相关资源
      最近更新 更多