Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: Dispatcher mapping problem

  1. #1
    Join Date
    Jan 2007
    Location
    Orlando, FL USA
    Posts
    84

    Default Dispatcher mapping problem

    Hi there,

    I wonder if any one has tried successfully mapping "/*" with spring's DispatcherServlet?

    Basically I want the following to work:
    Code:
    <servlet>
    		<servlet-name>webapp</servlet-name>
    		<servlet-class>
    			org.springframework.web.servlet.DispatcherServlet
    		</servlet-class>
    	</servlet>
    	<servlet-mapping>
    		<servlet-name>webapp</servlet-name>
    		<url-pattern>/*</url-pattern>
    	</servlet-mapping>
    I tried many configuration, and got those handler mapping to controller executed, but the ViewResolver don't seem able to resolve url correctly. I can see log reporting url can't be found that include the contextpath in front. Anyone has issue with this that can give me some pointer?

    Thanks,
    TBS.

  2. #2
    Join Date
    Jan 2007
    Location
    Orlando, FL USA
    Posts
    84

    Default

    Hello out there? So no one has experienced what I posted here? been few days and see no replies yet. I am still have no solution.

  3. #3
    Join Date
    Jan 2007
    Location
    Orlando, FL USA
    Posts
    84

    Default

    Hi, Can some one please give some advice with this problem?
    Much appreciated.
    -Z

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    We use it without any problem.

    Also if you want an answer including a bit more information (actuall error message, stacktraces, configuration etc.).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Jan 2007
    Location
    Orlando, FL USA
    Posts
    84

    Default

    mdeinum, Thks for taking interest.

    Please note that I am familiar with SpringMVC in general. I have created webapp with urls mapping/setup like these without any problems:
    Code:
    http://hostname/webappname/springdispathername/<mypath>
    http://hostname/webappname/<mypath>.dispatcher
    It's just bother me that I can't get mapping style working like following:
    Code:
    http://hostname/webappname/<mypath>
    When I run a webapp (eg: http://localhost:8080/myspringmvc/index) that has this config, I get a HTTP Status 404 page with the following logging:
    Code:
    09:52:25 INFO  org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/myspringmvc][log] - Initializing Spring FrameworkServlet 'webapp'
    09:52:25 INFO  org.springframework.web.servlet.DispatcherServlet[initServletBean] - FrameworkServlet 'webapp': initialization started
    09:52:25 INFO  org.springframework.web.context.support.XmlWebApplicationContext[prepareRefresh] - Refreshing org.springframework.web.context.support.XmlWebApplicationContext@779f5e: display name [WebApplicationContext for namespace 'webapp-servlet']; startup date [Mon Aug 20 09:52:25 EDT 2007]; root of context hierarchy
    09:52:26 INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader[loadBeanDefinitions] - Loading XML bean definitions from ServletContext resource [/WEB-INF/webapp-servlet.xml]
    09:52:26 INFO  org.springframework.web.context.support.XmlWebApplicationContext[obtainFreshBeanFactory] - Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext@779f5e]: org.springframework.beans.factory.support.DefaultListableBeanFactory@bcd14a
    09:52:26 INFO  org.springframework.beans.factory.support.DefaultListableBeanFactory[preInstantiateSingletons] - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@bcd14a: defining beans [controllerMapping,filenameViewController,internalViewResolver]; root of factory hierarchy
    09:52:26 INFO  org.springframework.web.servlet.DispatcherServlet[initServletBean] - FrameworkServlet 'webapp': initialization completed in 270 ms
    09:52:26 WARN  org.springframework.web.servlet.PageNotFound[noHandlerFound] - No mapping for [/myspringmvc/WEB-INF/view/index.jsp] in DispatcherServlet with name 'webapp'
    Here are more details of the project files:

    WEB-INF/view/index.jsp
    Code:
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    This is a demo for SpringMVC.
    <a href="/myapp/demo">/myspringmvc/demo</a>
    </body>
    </html>
    WEB-INF/webapp-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"
    	xmlns:util="http://www.springframework.org/schema/util" xmlns:lang="http://www.springframework.org/schema/lang"
    	xsi:schemaLocation="http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd
    	http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
    	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    	
    	<bean id="controllerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    		<property name="urlMap">
    			<util:map>
    				<entry key="index" value-ref="filenameViewController" />
    				<entry key="demo" value-ref="filenameViewController" />
    			</util:map>
    		</property>
    	</bean>
    	<bean id="filenameViewController" class="org.springframework.web.servlet.mvc.UrlFilenameViewController">
    	</bean>
    	<bean id="internalViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
    		<property name="prefix" value="WEB-INF/view/"></property>
    		<property name="suffix" value=".jsp"></property>
    	</bean>
    
    </beans>
    WEB-INF/web.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" 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">
    	<display-name>myspringmvc</display-name>
    
    	<servlet>
    		<servlet-name>webapp</servlet-name>
    		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    	</servlet>
    	<servlet-mapping>
    		<servlet-name>webapp</servlet-name>
    		<url-pattern>/*</url-pattern>
    	</servlet-mapping>
    
    </web-app>
    project directory structure
    Code:
    myspringmvc
    myspringmvc/.classpath
    myspringmvc/.project
    myspringmvc/.settings
    myspringmvc/.settings/org.eclipse.jdt.core.prefs
    myspringmvc/.settings/org.eclipse.jst.common.project.facet.core.prefs
    myspringmvc/.settings/org.eclipse.wst.common.component
    myspringmvc/.settings/org.eclipse.wst.common.project.facet.core.xml
    myspringmvc/build
    myspringmvc/build/classes
    myspringmvc/build/classes/log4j.properties
    myspringmvc/pom.xml
    myspringmvc/src
    myspringmvc/src/main
    myspringmvc/src/main/log4j.properties
    myspringmvc/web
    myspringmvc/web/META-INF
    myspringmvc/web/META-INF/MANIFEST.MF
    myspringmvc/web/WEB-INF
    myspringmvc/web/WEB-INF/lib
    myspringmvc/web/WEB-INF/view
    myspringmvc/web/WEB-INF/view/demo.jsp
    myspringmvc/web/WEB-INF/view/index.jsp
    myspringmvc/web/WEB-INF/web.xml
    myspringmvc/web/WEB-INF/webapp-servlet.xml
    So is there configuration that I missed?
    Thanks.

  6. #6
    Join Date
    Aug 2007
    Posts
    9

    Default re:

    take a look at my recent thread: http://forum.springframework.org/showthread.php?t=42820. well, i changed to the mapping "/*" and started having the same problem as you. my controller mapping is:

    <bean name="/login.htm" class="myapp.web.LoginController">

    using the url http://domain/myapp/login.htm i had these two situations:

    1 - using the mapping "<url-pattern>*.htm</url-pattern>" it worked well and i got the spring log:

    Code:
    ...JstlView] - <Rendering view with name 'login' with model {(...)} and static attributes {}>
    ...view.JstlView] - <Forwarded to resource [WEB-INF/jsp/login.jsp] in InternalResourceView 'login'>
    ...DispatcherServlet] - <Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@149f041>
    ...DispatcherServlet] - <Successfully completed request>
    2 - when i changed to "<url-pattern>/*</url-pattern>" it did not work and i got the logs:

    Code:
    ...JstlView] - <Rendering view with name 'login' with model {(...)} and static attributes {}>
    ...DispatcherServlet] - <Testing handler map [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@eb9dfa] in DispatcherServlet with name 'myapp'>
    ...SimpleUrlHandlerMapping] - <Looking up handler for [/WEB-INF/jsp/login.jsp]>
    ...DispatcherServlet] - <Testing handler map [org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping@2c5f8a] in DispatcherServlet with name 'myapp'>
    ...BeanNameUrlHandlerMapping] - <Looking up handler for [/WEB-INF/jsp/login.jsp]>
    ...DispatcherServlet] - <No handler found in getLastModified>
    ...DispatcherServlet] - <DispatcherServlet with name 'myapp' received request for [/myapp/WEB-INF/jsp/login.jsp]>
    ...DispatcherServlet] - <Bound request context to thread: org.apache.catalina.core.ApplicationHttpRequest@7af3e0>
    ...DispatcherServlet] - <Testing handler map [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@eb9dfa] in DispatcherServlet with name 'myapp'>
    ...SimpleUrlHandlerMapping] - <Looking up handler for [/WEB-INF/jsp/login.jsp]>
    ...DispatcherServlet] - <Testing handler map [org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping@2c5f8a] in DispatcherServlet with name 'myapp'>
    ...BeanNameUrlHandlerMapping] - <Looking up handler for [/WEB-INF/jsp/login.jsp]>
    ...WARN [org.springframework.web.servlet.PageNotFound] - <No mapping for [/myapp/WEB-INF/jsp/login.jsp] in DispatcherServlet with name 'myapp'>
    ...DispatcherServlet] - <Cleared thread-bound request context: org.apache.catalina.core.ApplicationHttpRequest@7af3e0>
    ...DispatcherServlet] - <Successfully completed request>
    note that after "Rendering view with name 'login'" it tries to locate a mapping for "myapp" and do not find it. so maybe the problem is that the mappings in myapp-servlet.xml are missing something.

  7. #7
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    I think the problem might be that it creates some kind of loop, due to the mapping of /*. I checked our configuration and we use a *.htm notation.

    Can you create a small sample project that I can use for debugging? I will take a closer look.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  8. #8
    Join Date
    Jan 2007
    Location
    Orlando, FL USA
    Posts
    84

    Default

    Thanks for give it a shot guys. As I have mentioned earlier, I don't have problem getting it work with a extension mapping. But I am curious as why won't a "/*" mapping won't work.

    Attached is a eclipse project that contains files I presented in this post. It's very simple project that depends only on spring and logging and jstl jars.

    The project is configured with Maven Eclipse Plugin that auto download all jars and it can be install by this update site: http://m2eclipse.codehaus.org/update

    And the project is runable by a Tomcat runtime server inside Eclipse. I am using Tomcat 5.5.

    Please do let me know if anyone of you find a solution.

  9. #9
    Join Date
    Jan 2007
    Location
    Orlando, FL USA
    Posts
    84

    Default

    Hum... attachment doesn't seem to work.

    See if you guys can download it here
    http://cl1p.net/myspringmvc

    Or email at
    thebugslayer at gmail dot com.

    Thanks.
    Last edited by thebugslayer; Aug 20th, 2007 at 04:10 PM.

  10. #10

    Default

    Im not so sure you would find /* mapping to be useful; wouldnt that also push all requests for simple static items such as style sheets and images through the servlet as well? Doesnt seem like it is what you are looking for; I bet you would find extension mapping to be your answer (e.g. *.htm, you can even map *.jsp to the spring dispatcher, and it will override the server's implicit mapping for jsp files if you like).

Posting Permissions

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