Results 1 to 8 of 8

Thread: Problem with View Resolver

  1. #1
    Join Date
    Apr 2011
    Posts
    5

    Default Problem with View Resolver

    Hi, i have a problem with my spring project.

    Here is my web.xml

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <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">
    
        <servlet>
            <servlet-name>greenmine</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>greenmine</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
    
        <welcome-file-list>
            <welcome-file>
                index.jsp
            </welcome-file>
        </welcome-file-list>
    
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                /WEB-INF/greenmine-servlet.xml
            </param-value>
        </context-param>
    
        <filter>
            <filter-name>springSecurityFilterChain</filter-name>
            <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
        </filter>
    
        <filter-mapping>
            <filter-name>springSecurityFilterChain</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
    
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    </web-app>
    and my greenmine-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:context="http://www.springframework.org/schema/context"
        xmlns:security="http://www.springframework.org/schema/security"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-3.0.xsd
           http://www.springframework.org/schema/security
           http://www.springframework.org/schema/security/spring-security-3.0.3.xsd
           http://www.springframework.org/schema/mvc
           http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    
        <context:component-scan base-package="at.tripwire.greenmine.controller" />
        <context:component-scan base-package="at.tripwire.greenmine.domain.dao" />
        <context:component-scan base-package="at.tripwire.greenmine.service" />
        <context:component-scan base-package="at.tripwire.greenmine.module" />
    
        <mvc:annotation-driven />
        <mvc:resources location="/css/" mapping="/css/**" />
        <mvc:resources location="/images/" mapping="/images/**" />
        <mvc:resources location="/js/" mapping="/js/**" />
    
        <bean id="viewResolver"
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
            <property name="prefix" value="/WEB-INF/jsp/" />
            <property name="suffix" value=".jsp" />
        </bean>
    
        <!-- Hibernate Configuration -->
        <bean id="dataSource"
            class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName">
                <value>com.mysql.jdbc.Driver</value>
            </property>
            <property name="url">
                <value>jdbc:mysql://localhost/greenmine</value>
            </property>
            <property name="username">
                <value>root</value>
            </property>
            <property name="password">
                <value>root</value>
            </property>
        </bean>
    
        <bean id="sessionFactory"
            class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
            <property name="annotatedClasses">
                <list>
                    <value>at.tripwire.greenmine.domain.Project</value>
                    <value>at.tripwire.greenmine.domain.Profile</value>
                </list>
            </property>
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
                    <prop key="hibernate.hbm2ddl.auto">update</prop>
                </props>
            </property>
            <property name="dataSource">
                <ref bean="dataSource" />
            </property>
        </bean>
    
        <!-- Spring Security -->
        <security:http auto-config="true" use-expressions="true">
            <security:intercept-url pattern="/login"
                access="permitAll" />
            <security:intercept-url pattern="/j_spring_security_check"
                access="permitAll" />
            <security:intercept-url pattern="/css/**"
                filters="none" />
            <security:intercept-url pattern="/js/**"
                filters="none" />
            <security:intercept-url pattern="/images/**"
                filters="none" />
            <security:intercept-url pattern="/**"
                access="isAuthenticated()" />
            <security:form-login login-page="/login"
                login-processing-url="/j_spring_security_check" default-target-url="/projects"
                authentication-failure-url="/login?error=1" />
            <security:logout logout-success-url="/login"
                logout-url="/logout" />
        </security:http>
    
        <security:authentication-manager>
            <security:authentication-provider
                user-service-ref="profileUserDetailsService">
                <security:password-encoder hash="md5" />
            </security:authentication-provider>
        </security:authentication-manager>
    </beans>
    next: my LoginController.java

    Code:
    @Controller
    public class LoginController {
    
        @RequestMapping("/login")
        public ModelAndView handleLoginForm(HttpServletRequest request) {
            String errParam = request.getParameter("error");
            ModelAndView mv = new ModelAndView("login/login");
            if(errParam != null) {
                mv.addObject("error", "Benutzer oder Kennwort unzul&auml;ssig");
            }
            return mv;
        }
    }
    I am using Winstone Servlet Engine v0.9.10. When i goto http://localhost:8080/login it puts following error:

    Code:
    14.04.2011 21:48:13 org.springframework.web.servlet.DispatcherServlet noHandlerFound
    WARNUNG: No mapping found for HTTP request with URI [/WEB-INF/jsp/login/login.jsp] in DispatcherServlet with name 'greenmine'
    but login.jsp is in WEB-INF/jsp/login/login.jsp
    hope anyone can help me. i am already searching for two weeks.

  2. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    Hello


    Code:
     <bean id="viewResolver"
           class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
            <property name="prefix" value="/WEB-INF/jsp/" />
            <property name="suffix" value=".jsp" />
        </bean>
    With the orange part your application expect find all the jsp only in such level, not within such level, thats because the next fails

    Code:
     ModelAndView mv = new ModelAndView("login/login");
    Code:
    14.04.2011 21:48:13 org.springframework.web.servlet.DispatcherServlet noHandlerFound
    WARNUNG: No mapping found for HTTP request with URI 
    [/WEB-INF/jsp/login/login.jsp] in DispatcherServlet with name 'greenmine'
    1) consider work with ResourceBundleViewResolver if you want explicity define each path jsp file file within views.properties (explicitly read this 16.3.2.2. ResourceBundleViewResolver ), here (15.5 Resolving views) more information about views

    2) why you are controlling the jsp view login name?, Spring Security handles well this, and even you are defining

    Code:
    <security:form-login login-page="/login"
                  login-processing-url="/j_spring_security_check" 
                  default-target-url="/projects"
                  authentication-failure-url="/login?error=1" />
    <security:logout logout-success-url="/login"  logout-url="/logout" />
    HTH
    Last edited by dr_pompeii; Apr 15th, 2011 at 07:56 PM.
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  3. #3
    Join Date
    Apr 2011
    Posts
    5

    Default

    Thank you for your answer!

    But, is there another possibility to handle the jsp in InternalResourceViewResolver or any other ViewResolver? I don't want to handle each jsp file in a property file.

  4. #4
    Join Date
    Apr 2011
    Posts
    5

    Default

    Now i am using the ResourceBundleViewResolver but the same error occurs:

    Code:
    16.04.2011 10:18:56 org.springframework.web.servlet.DispatcherServlet noHandlerFound
    WARNUNG: No mapping found for HTTP request with URI [/WEB-INF/jsp/login/login.jsp] in DispatcherServlet with name 'greenmine'
    ViewResolver in Servlet
    Code:
    <bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
    	  <property name="basename" value="views"/>
    	</bean>
    ViewProperties
    Code:
    login.(class)=org.springframework.web.servlet.view.JstlView
    login.url=WEB-INF/jsp/login/login.jsp
    and the modified Controller
    Code:
    @Controller
    public class LoginController {
    
    	@RequestMapping("/login")
    	public ModelAndView handleLoginForm(HttpServletRequest request) {
    		String errParam = request.getParameter("error");
    		ModelAndView mv = new ModelAndView("login");
    		if(errParam != null) {
    			mv.addObject("error", "Benutzer oder Kennwort unzul&auml;ssig");
    		}
    		return mv;
    	}
    }

  5. #5
    Join Date
    Apr 2011
    Posts
    5

    Default

    nobody can help me?

  6. #6
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    Hello

    nobody can help me?
    I am alone working with a project, therefore you know the reason of my delay

    But, is there another possibility to handle the jsp in InternalResourceViewResolver or any other ViewResolver? I don't want to handle each jsp file in a property file.
    I afraid not, I dont know if wild cards are supported here, but is better have each one declared

    1) about ViewProperties , should be views.properties the file name
    2) About

    Code:
    login.(class)=org.springframework.web.servlet.view.JstlView
    login.url=WEB-INF/jsp/login/login.jsp
    Be totally sure that no empty space exists after each line

    3) Be aware your using this /login in two places

    in your controller @RequestMapping("/login")
    and with in Spring Security

    Code:
     
    <security:form-login login-page="/login"
                  login-processing-url="/j_spring_security_check" 
                  default-target-url="/projects"
                  authentication-failure-url="/login?error=1" />
    <security:logout logout-success-url="/login"
                  logout-url="/logout" />
    I insist, why you are doing this?
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  7. #7
    Join Date
    Sep 2009
    Location
    Vilnius, Lithuania
    Posts
    118

    Default

    InternalResourceViewResolver is perfectly capable of resolving nested paths. In fact, it did resolve "login/login" view name into /WEB-INF/jsp/login/login.jsp, so it works as expected.

    The problem with your configuration is that DispatcherServlet is the default servlet (as it is mapped to "/") so it handles every request, including forwarded JSP rendering requests. So what happens is that /WEB-INF/jsp/login/login.jsp is processed (again) as a URL by DispatcherServlet, but this time it cannot be resolved because no controller can handle this URL.

    What you need to do is to delegate JSP rendering to your web container's (e.g. Tomcat's) default servlet. This can be done with this simple line of configuration:

    Code:
    <mvc:default-servlet-handler/>

  8. #8
    Join Date
    Apr 2011
    Posts
    5

    Default

    Quote Originally Posted by Osvaldas Grigas View Post
    InternalResourceViewResolver is perfectly capable of resolving nested paths. In fact, it did resolve "login/login" view name into /WEB-INF/jsp/login/login.jsp, so it works as expected.

    The problem with your configuration is that DispatcherServlet is the default servlet (as it is mapped to "/") so it handles every request, including forwarded JSP rendering requests. So what happens is that /WEB-INF/jsp/login/login.jsp is processed (again) as a URL by DispatcherServlet, but this time it cannot be resolved because no controller can handle this URL.

    What you need to do is to delegate JSP rendering to your web container's (e.g. Tomcat's) default servlet. This can be done with this simple line of configuration:

    Code:
    <mvc:default-servlet-handler/>
    thank you, that solved my problem

Posting Permissions

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