0

I want to create 2 view resolvers for .jsp and .xhtml pages I've tried multiple times and the process failed I have the .jsp view resolver as the highest priority view resolver It works fine with .jsp pages but when it comes to .xhtml pages it gives me an error: resource not found So it does not process the ".xhtml" view resolver in case the ".jsp" view is not found here is the screenshot of the error and the project achitecture: http://postimg.org/image/5cz5iulwd/

Below are the web.xml servle-context.xml and applicationContext.xml codes What should I do?

web.xml -->

<!-- Spring Security -->
<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>
    <dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:applicationContext.xml</param-value>
</context-param>

<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
<!-- xhtml mapping -->
<servlet> 
    <servlet-name>FacesServlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>FacesServlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

applicationContext.xml --->

enter code here <!-- datasource -->
<bean id="datasource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost:3306/primefaces"/>
    <property name="username" value="root"/>
    <property name="password" value=""/>
</bean>
<!-- persistenceUnitManager -->
<bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
    <property name="defaultDataSource" ref="datasource"/>
    <property name="persistenceXmlLocations">
        <list>
            <value>classpath*:META-INF/persistence.xml</value>
        </list>
    </property>
</bean>
<!-- entityManagerFactory -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitManager" ref="persistenceUnitManager"/>
    <property name="persistenceUnitName" value="UP_TEST"/>
</bean>
<!-- transactionManager -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<context:annotation-config/>
<bean id="dao" class="com.test.app.dao.DaoIml"></bean>
<bean id="metier" class="com.test.app.metier.MetierIml">
    <property name="dao" ref="dao"></property>
</bean>
<s:http  use-expressions="true">
    <s:intercept-url pattern="/admin/**" access="ROLE_ADMIN"/>
    <s:form-login login-page="/login" default-target-url="/default" authentication-failure-url="/login" />
    <s:logout logout-success-url="/login" />
</s:http>
<s:authentication-manager>
    <s:authentication-provider>
        <s:password-encoder hash="md5"></s:password-encoder>
        <s:jdbc-user-service data-source-ref="datasource" users-by-username-query="select user_name,password, actived from users where user_name=?" authorities-by-username-query="select u.user_name, r.roleName from users u, role r where u.user_id = r.user_id and u.user_name =? " />
    </s:authentication-provider>
</s:authentication-manager>

and here is the servlet-context.xml

<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />

<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />

 <beans:bean id="viewResolver"
   class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<beans:property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></beans:property>
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" /> 
<beans:property name="order" value="0" />
</beans:bean>


<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="/WEB-INF/views/" />
    <beans:property name="suffix" value=".xhtml" />
      <beans:property name="order" value="1" />
</beans:bean>

<context:component-scan base-package="com.test.app" />
1
  • one question, why not serve your xhtml files as static resources? Commented Feb 10, 2015 at 0:25

1 Answer 1

1

Looks like you cannot chain InternalResourceViewResolver and UrlBasedViewResolver together. InternalResourceViewResolver extends UrlBasedViewResolver. The blog "blog.frankel.ch/chaining-url-view-resolvers-in-spring-mvc"; can give you an option

Sign up to request clarification or add additional context in comments.

3 Comments

Tried it changed the xhtml view resolver(url based) to order 0 and the jsp view resolver(internal view resolver) to order 1 and it tells me that the can't find the "login.xhtml" file (which I want to open) and gave me this error: s7.postimg.org/cu2b4ld0r/err.png
I could not see what the error is in the screen shot. Can you post a different image or post the error here.
Looks like you cannot chain InternalResourceViewResolver and UrlBasedViewResolver together. InternalResourceViewResolver extends UrlBasedViewResolver. The blog "blog.frankel.ch/chaining-url-view-resolvers-in-spring-mvc" can give you an option. Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.