配置web.xml不使用pageContext.request.contextPath?

时间:2013-08-27 18:01:22

标签: java spring hibernate spring-mvc extjs

你好我有一个带有Hibernate的Spring MVC的应用程序,但问题是我没有配置得很正确因为路由,为了导入库.js和.css,我必须使用pageContext.request.contextPath,我显示了我的设置:

•web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">
    <display-name>extjs_commerceapp-solution</display-name>
    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>login.jsp</welcome-file>
    </welcome-file-list>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
              /WEB-INF/commerceapp-servlet.xml
          </param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>commerceapp</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    </servlet>    
    <servlet-mapping>
        <servlet-name>commerceapp</servlet-name>
        <url-pattern>/mvc/*</url-pattern>
    </servlet-mapping>
</web-app>

•commerceapp-servlet.xml

<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: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/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        ">
    <mvc:annotation-driven />
    <context:component-scan base-package="com.limati.commerceapp" />
    <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/com/limati/commerceapp/" />
        <property name="suffix" value=".jsp" />
    </bean>
    <!-- Configures Hibernate - Database Config -->
    <import resource="commerceapp-dao-hibernate.xml" />
    <import resource="commerceapp-service.xml" />
</beans>

通过commerceapp-servlet.xml,我导入了另外两个我的设置Hibernate XML。 问题是我的主页面加载了我的RIA界面,我必须把这个路由( pageContext.request.contextPath ):

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>CommerceApp</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/ext4/resources/css/ext-all.css"/>
<script type="text/javascript" src="${pageContext.request.contextPath}/ext4/ext-all-debug.js"></script>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/resources/css/app.css"/>
    </head>
    <body style="background-color: #95B0CD" >
        <script type="text/javascript">
            Ext.Loader.setConfig({
                enabled: true,
                paths:{
                    "app": "${pageContext.request.contextPath}/app"
                }
            });  
            var CONTEXT_PATH = "${pageContext.request.contextPath}";
            var USER = "${sessionScope.user.userName}";
            app=Ext.create('Ext.app.Application',{
                name:'LTI',
                appFolder: 'app/base/user',
                //controllers:['UserController'],    //si se quiere inicializar un controlador en la creación
                launch: function(){        
                    Ext.create("app.principal.view.Desktop",{
                    });      
                }        
            });

        </script>
    </body>
</html>

有人可以帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

我认为你必须添加这个标签

<mvc:resources mapping="/resources/**" location="/resources/" />

处理静态资源。将所有静态资源放在资源文件夹中,或者根据需要更改位置。