Results 1 to 5 of 5

Thread: newbie problem with url mapping

  1. #1
    Join Date
    Jan 2008
    Location
    Pittsburgh, PA
    Posts
    6

    Default newbie problem with url mapping

    Hi, I'm new to using Spring, so this is probably something really silly I'm missing. I've been bashing my head though, so hopefully you can point out the problem for me.

    I've been following tutorials to make a simple Hello World app. However, my requests to hello.html are not being forwarded to my HelloController. Instead, I just get an error that says the servlet springapp is not available. The catalina log files look fine to me though.

    Any help is appreciated. Thanks!

    web.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.4"
             xmlns="http://java.sun.com/sml/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">
             
       <servlet>
       		<servlet-name>springapp</servlet-name>
       		<servlet-class>org.springframework.web.servlet.DispatchServlet</servlet-class>
       		<load-on-startup>1</load-on-startup>
       	</servlet>
       	     
        <servlet-mapping>
       		<servlet-name>springapp</servlet-name>
       		<url-pattern>*.html</url-pattern>
       	</servlet-mapping>      
             
       <welcome-file-list>
       	<welcome-file>
       	index.jsp
       	</welcome-file>
       	</welcome-file-list>
    </web-app>
    springapp-servlet.xml

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <beans xmlns="http://www.springframework.org/schema/beans"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://www.springframework.org/schema/beans
             http://www/springframework.org/schema/beans/spring-beans-2.5.xsd">
             
    	<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        	<property name="mappings">
        		<props>
        			<prop key="/hello.html">hello</prop>
        		</props>
        	</property>
    	</bean>
             
    	<bean id="hello" class="springapp.web.HelloController"/>
    </beans>
    catalina.out snippet:
    Code:
    Mar 21, 2008 3:48:20 PM org.apache.catalina.startup.HostConfig deployWAR
    INFO: Deploying web application archive springapp.war
    Mar 21, 2008 3:51:01 PM org.apache.catalina.startup.HostConfig checkResources
    INFO: Undeploying context [/springapp]
    Mar 21, 2008 3:51:01 PM org.apache.catalina.startup.HostConfig deployWAR
    INFO: Deploying web application archive springapp.war
    Mar 21, 2008 3:53:12 PM org.apache.catalina.core.StandardContext reload
    INFO: Reloading this Context has started
    Ciera N.C. Jaspan
    Graduate Research Assistant
    Institute for Software Research
    Carnegie Mellon University

  2. #2
    Join Date
    Jul 2005
    Location
    Idaho
    Posts
    231

    Default

    ciera,

    You need a PropertiesMethodNameResolver.
    Code:
        
    <bean id="hello" class="springapp.web.HelloController"> 
      <property name="methodNameResolver" ref="helloResolver"/> 
    </bean>
    
    <bean id="helloResolver"> class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver"> 
      <property name="mappings"> 
        <props> 
          <prop key="/hello.htm">helloHandler</prop> 
        </props> 
      </property> 
    </bean>
    Good luck

    Steve O

  3. #3
    Join Date
    Jan 2008
    Location
    Pittsburgh, PA
    Posts
    6

    Default

    This did not appear to fix the problem. My springapp-servlet.xml now looks like this:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <beans xmlns="http://www.springframework.org/schema/beans"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://www.springframework.org/schema/beans
             http://www/springframework.org/schema/beans/spring-beans-2.5.xsd">
             
    	<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        	<property name="mappings">
        		<props>
        			<prop key="/hello.html">hello</prop>
        		</props>
        	</property>
    	</bean>
             
    	<bean id="hello" class="springapp.web.HelloController">
    	  <property name="methodNameResolver" ref="helloResolver"/> 
    	</bean>
    
    	<bean id="helloResolver" class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver"> 
    	  <property name="mappings"> 
    	    <props> 
    	      <prop key="/hello.html">helloHandler</prop> 
    	    </props> 
    	  </property> 
    	</bean>
    </beans>
    All other symptoms are the same.
    Ciera N.C. Jaspan
    Graduate Research Assistant
    Institute for Software Research
    Carnegie Mellon University

  4. #4
    Join Date
    Jul 2005
    Location
    Idaho
    Posts
    231

    Default

    ciera,

    Do you have a viewResolver? Does your HelloController have a helloHandler() method in it?

    I think that you are missing something minor. Maybe turn up your debugging level up to the debug level. If you are using Tomcat, use the manager to deploy the war and watch the logs. Post any pertinent logging messages.

    Steve O

  5. #5
    Join Date
    Jan 2008
    Location
    Pittsburgh, PA
    Posts
    6

    Default

    I don't know what a viewResolver is, so presumably I don't have one. My HelloController is just a simple HelloWorld, as shown below.

    I'm not sure how to change the log levels on Tomcat. A Google search only suggested files that don't seem to exist. I'm using Tomcat 5.5.26.

    I'm deploying with an Ant script. It's copying in the war file and then using the Tomcat manager to reload.

    This is the most frustrating Hello World app I have ever written.

    Code:
    package springapp.web;
    
    import java.io.IOException;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.springframework.web.servlet.mvc.Controller;
    import org.springframework.web.servlet.ModelAndView;
    
    public class HelloController implements Controller {
    	
    	protected final Log logger = LogFactory.getLog(getClass());
    
    	public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
    	  throws ServletException, IOException {
    		logger.info("returning Hello view");
    		return new ModelAndView("hello.jsp");
    	}
    
    }
    Ciera N.C. Jaspan
    Graduate Research Assistant
    Institute for Software Research
    Carnegie Mellon University

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •