我试图对我的控制器进行更改,突然间,我似乎不再接收任何请求(404尝试命中servlet映射的URL时)。我确定我已经打破了我的web.xml
或app-servlet.xml
,但我只是看不到。我可以从tomcat(index.jsp
)访问http://IP/app/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>
答案 0 :(得分:2)
你的控制器映射应该看起来更像这样,首先关闭,但你的URL“模式”看起来也很可疑,模式很少是你拥有的静态字符串,但如果你想要的是URL“/ myRequest”映射在您的控制器中,您只需要以下内容:
<bean name = "/myRequest" class = "com.stefankendall.MyController" ></bean>
答案 1 :(得分:0)
<url-pattern>/myRequest</url-pattern>
应为<url-pattern>/myRequest/*</url-pattern>