Announcement Announcement Module
Collapse
No announcement yet.
annotations problem. error: The requested resource is not available. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • annotations problem. error: The requested resource is not available.

    Hi,
    I am new to spring and I am trying to create an annotations based Spring project, but my problem is that the when I submit the form, I get the error:

    type Status report

    message /show.do

    description The requested resource (/show.do) is not available.


    I am using Eclipse with Tomcat 6.0 and the hierarchy of the project is:
    http://forum.springsource.org/pictur...&pictureid=113

    The web.xml file is:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.4">
    <servlet>
    <servlet-name>SpringSongs</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
    <load-on-startup> 1 </load-on-startup>
    </servlet>

    <servlet-mapping>
    <servlet-name>SpringSongs</servlet-name>
    <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    </web-app>

    SpringSongs-servlet.xml file is:
    <?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="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schem...-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan base-package="com.test.music"/>

    <bean class="org.springframework.web.servlet.mvc.annotat ion.DefaultAnnotationHandlerMapping"/>

    <bean class="org.springframework.web.servlet.mvc.annotat ion.AnnotationMethodHandlerAdapter"/>

    <bean id="jspViewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlVi ew"/>
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
    </bean>


    </beans>

    And Controller file is:

    Code:
    package com.test.music;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    
    @Controller
    
    public class TestController {
    	@RequestMapping(value = "/show.do", method = RequestMethod.POST)
    	public void show(HttpServletResponse response, HttpServletRequest request){
    		System.out.println("here!");
    	}
    	
    	
    }
    I can see a line in the log:
    INFO: Mapped URL path [/show.do] onto handler 'testController'


    Can you please let me know what the issue is?
    Thanks
    Last edited by blinkaj; Mar 14th, 2011, 11:54 PM. Reason: wrong xml file name entered

  • #2
    Re:- annotations problem. error: The requested resource is not available.

    Hi,
    I just developed the same application as u have mention in the forum.
    In the web.xml

    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml,/WEB-INF/dispatcher-servlet.xml</param-value>
    </context-param>
    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>
    <servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
    <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>*.htm</url-pattern>
    </servlet-mapping>

    changes need to be done . In the contextConfigLocation tag the dispatcher-Servlet.xml need to be added so that the file get loaded on startup of server.

    In the dispatcher-Servlet.xml the below code need to be added

    <ns1:component-scan base-package="com.test.music">
    </ns1:component-scan>

    <bean class="org.springframework.web.servlet.mvc.annotat ion.DefaultAnnotationHandlerMapping">
    <property name="order" value="1" />
    </bean>
    <bean class="org.springframework.web.servlet.handler.Bea nNameUrlHandlerMapping">
    <property name="order" value="2" />
    </bean>


    <bean id="viewResolver"
    class="org.springframework.web.servlet.view.Intern alResourceViewResolver"
    prefix="/WEB-INF/jsp/"
    p:suffix=".jsp" />

    The class BeanNameUrlHandlerMapping will help U mapping the MAV object to URL.

    Regards

    Comment


    • #3
      correcting the path in the mapping in jsp

      thanks for your reply. I tried using your suggestion but it didn't work. Then I became pretty sure that its a path issue. So I tried ../show.do in jsp rather then just /show.do, with my code which I have shown above, and it worked .

      The thing is that its not necessary to mention contextConfigLocation explicity in the web.xml. If you don't provide it, the dispatcher servlet will look for default xml file which is [servletname]-servlet.xml. You can have the bean configurations in this xml file.

      thanks again.

      Comment

      Working...
      X