views:

136

answers:

3

I was attempting to make changes to my controller, and all of a sudden, I no longer seem to receive any requests (404 when attempting to hit the servlet mapped URLs). I'm sure I've broken my web.xml or app-servlet.xml, but I just don't see where. I can access index.jsp from tomcat (http://IP/app/index.jsp), but I can't get my servlet mapping to work correctly.

Help?

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"&gt;
<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"&gt;

<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"&gt;
<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>
A: 

<url-pattern>/myRequest</url-pattern> should be <url-pattern>/myRequest/*</url-pattern>

axtavt
A: 

You have /myRequest in both your web.xml and Spring URL mapping. You should put it on one or the other, most likely by removing it from the Spring mapping:

<prop key="/">MyController</prop>

The Spring mapping is done relative to the servlet path, and the servlet path is defined by the web.xml as /myRequest.

skaffman
While this makes sense, I still receive a 404 with this mapping.
Stefan Kendall
Out of interest, try the URL ending with `/`, i.e. `http://myhost/myRequest/`
skaffman
Still gets a 404. :/
Stefan Kendall
while it may have not gotten your code to work (for what could be many other reasons not included in your code example) the code that he provided is still an improvement over what was already there, to vote it down is not very polite
walnutmon
Polite or not, it's still wrong and doesn't solve my issue. Voting up blatantly incorrect answers is not the model of StackOverflow. Bad answers should be downvoted and deled, and good answers should be upvoted and accepted. If this WASN'T intended, it wouldn't be more expensive to be penalized than to actually downvote.
Stefan Kendall
By the same token, voting down answers that aren't 100% correct is a good way of discouraging others from trying.
skaffman
On the contrary. I think it's a way to encourage others to try harder. If you want points, post correct answers.
Stefan Kendall
Not working out so great for you on this one, though, is it....
skaffman
A: 

your controller mapping should look more like this, first off, but your URL "pattern" looks fishy too, a pattern is rarely a static string as you have it, but if what you want is the URL "/myRequest" mapped to your controller the following is all you need:

<bean name = "/myRequest" class = "com.stefankendall.MyController" ></bean>
walnutmon
Not workin geitehr, even when I specify a name, rather than id, as is forced.
Stefan Kendall